Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comma in values fix #256

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions dist/much-select-elm-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -13121,17 +13121,23 @@ var $author$project$Ports$valuesDecoder = $elm$json$Json$Decode$oneOf(
$elm$json$Json$Decode$list($elm$json$Json$Decode$string),
A2($elm$json$Json$Decode$map, $elm$core$List$singleton, $elm$json$Json$Decode$string)
]));
var $author$project$SelectedValueEncoding$stringToValueStrings = F2(
function (selectedValueEncoding, valuesString) {
var $author$project$SelectedValueEncoding$stringToValueStrings = F3(
function (config, selectedValueEncoding, valuesString) {
if ((valuesString === '') && _Utils_eq(selectedValueEncoding, $author$project$SelectedValueEncoding$CommaSeperated)) {
return $elm$core$Result$Ok(_List_Nil);
} else {
if ((valuesString === '') && _Utils_eq(selectedValueEncoding, $author$project$SelectedValueEncoding$JsonEncoded)) {
return $elm$core$Result$Ok(_List_Nil);
} else {
if (selectedValueEncoding.$ === 'CommaSeperated') {
return $elm$core$Result$Ok(
A2($elm$core$String$split, ',', valuesString));
if (config.$ === 'SingleSelectConfig') {
return $elm$core$Result$Ok(
_List_fromArray(
[valuesString]));
} else {
return $elm$core$Result$Ok(
A2($elm$core$String$split, ',', valuesString));
}
} else {
return A2(
$elm$core$Result$andThen,
Expand Down Expand Up @@ -13275,7 +13281,7 @@ var $author$project$MuchSelect$init = function (flags) {
var selectionConfig = _v10.a;
var selectionConfigErrorEffect = _v10.b;
var _v12 = function () {
var _v13 = A2($author$project$SelectedValueEncoding$stringToValueStrings, selectedValueEncoding, flags.selectedValue);
var _v13 = A3($author$project$SelectedValueEncoding$stringToValueStrings, selectionConfig, selectedValueEncoding, flags.selectedValue);
if (_v13.$ === 'Ok') {
var values = _v13.a;
return _Utils_Tuple2(values, $author$project$MuchSelect$NoEffect);
Expand Down Expand Up @@ -19460,7 +19466,7 @@ var $author$project$MuchSelect$update = F2(
}),
$author$project$MuchSelect$NoEffect);
case 'selected-value':
var _v43 = A2($author$project$SelectedValueEncoding$stringToValueStrings, model.selectedValueEncoding, newAttributeValue);
var _v43 = A3($author$project$SelectedValueEncoding$stringToValueStrings, model.selectionConfig, model.selectedValueEncoding, newAttributeValue);
if (_v43.$ === 'Ok') {
var selectedValueStrings = _v43.a;
if (A2($author$project$OptionList$selectedOptionValuesAreEqual, selectedValueStrings, model.options)) {
Expand Down
18 changes: 12 additions & 6 deletions dist/much-select-elm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7763,17 +7763,23 @@ var $author$project$Ports$valuesDecoder = $elm$json$Json$Decode$oneOf(
$elm$json$Json$Decode$list($elm$json$Json$Decode$string),
A2($elm$json$Json$Decode$map, $elm$core$List$singleton, $elm$json$Json$Decode$string)
]));
var $author$project$SelectedValueEncoding$stringToValueStrings = F2(
function (selectedValueEncoding, valuesString) {
var $author$project$SelectedValueEncoding$stringToValueStrings = F3(
function (config, selectedValueEncoding, valuesString) {
if ((valuesString === '') && (!selectedValueEncoding)) {
return $elm$core$Result$Ok(_List_Nil);
} else {
if ((valuesString === '') && (selectedValueEncoding === 1)) {
return $elm$core$Result$Ok(_List_Nil);
} else {
if (!selectedValueEncoding) {
return $elm$core$Result$Ok(
A2($elm$core$String$split, ',', valuesString));
if (!config.$) {
return $elm$core$Result$Ok(
_List_fromArray(
[valuesString]));
} else {
return $elm$core$Result$Ok(
A2($elm$core$String$split, ',', valuesString));
}
} else {
return A2(
$elm$core$Result$andThen,
Expand Down Expand Up @@ -7917,7 +7923,7 @@ var $author$project$MuchSelect$init = function (flags) {
var selectionConfig = _v10.a;
var selectionConfigErrorEffect = _v10.b;
var _v12 = function () {
var _v13 = A2($author$project$SelectedValueEncoding$stringToValueStrings, selectedValueEncoding, flags.bE);
var _v13 = A3($author$project$SelectedValueEncoding$stringToValueStrings, selectionConfig, selectedValueEncoding, flags.bE);
if (!_v13.$) {
var values = _v13.a;
return _Utils_Tuple2(values, $author$project$MuchSelect$NoEffect);
Expand Down Expand Up @@ -14156,7 +14162,7 @@ var $author$project$MuchSelect$update = F2(
}),
$author$project$MuchSelect$NoEffect);
case 'selected-value':
var _v43 = A2($author$project$SelectedValueEncoding$stringToValueStrings, model.h, newAttributeValue);
var _v43 = A3($author$project$SelectedValueEncoding$stringToValueStrings, model.a, model.h, newAttributeValue);
if (!_v43.$) {
var selectedValueStrings = _v43.a;
if (A2($author$project$OptionList$selectedOptionValuesAreEqual, selectedValueStrings, model.b)) {
Expand Down
8 changes: 8 additions & 0 deletions run-pty.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"title": "Build much-select for development",
"command": [
"watchexec",
"--project-origin",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested locally and i can still run successfully with this so im good with these changes 👍🏻

".",
"-w",
"src",
"--",
Expand Down Expand Up @@ -32,6 +34,8 @@
"title": "Build HTML for demo/sandbox site",
"command": [
"watchexec",
"--project-origin",
".",
"-w",
"site",
"-w",
Expand Down Expand Up @@ -61,6 +65,8 @@
"title": "Elm tests",
"command": [
"watchexec",
"--project-origin",
".",
"-w",
"src",
"-w",
Expand All @@ -82,6 +88,8 @@
"title": "Build much-select for production",
"command": [
"watchexec",
"--project-origin",
".",
"-w",
"src",
"--",
Expand Down
4 changes: 2 additions & 2 deletions src/MuchSelect.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ update msg model =
)

"selected-value" ->
case SelectedValueEncoding.stringToValueStrings model.selectedValueEncoding newAttributeValue of
case SelectedValueEncoding.stringToValueStrings model.selectionConfig model.selectedValueEncoding newAttributeValue of
Ok selectedValueStrings ->
if OptionList.selectedOptionValuesAreEqual selectedValueStrings model.options then
( model, NoEffect )
Expand Down Expand Up @@ -3395,7 +3395,7 @@ init flags =
|> Result.withDefault SelectedValueEncoding.defaultSelectedValueEncoding

( initialValues, initialValueErrEffect ) =
case SelectedValueEncoding.stringToValueStrings selectedValueEncoding flags.selectedValue of
case SelectedValueEncoding.stringToValueStrings selectionConfig selectedValueEncoding flags.selectedValue of
Ok values ->
( values, NoEffect )

Expand Down
13 changes: 9 additions & 4 deletions src/SelectedValueEncoding.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Json.Encode
import Option exposing (Option)
import OptionList exposing (OptionList)
import Ports exposing (valueDecoder, valuesDecoder)
import SelectionMode exposing (SelectionMode)
import SelectionMode exposing (SelectionConfig(..), SelectionMode)
import Url exposing (percentDecode, percentEncode)


Expand Down Expand Up @@ -59,8 +59,8 @@ toString selectedValueEncoding =
"json"


stringToValueStrings : SelectedValueEncoding -> String -> Result String (List String)
stringToValueStrings selectedValueEncoding valuesString =
stringToValueStrings : SelectionConfig -> SelectedValueEncoding -> String -> Result String (List String)
stringToValueStrings config selectedValueEncoding valuesString =
if valuesString == "" && selectedValueEncoding == CommaSeperated then
Ok []

Expand All @@ -70,7 +70,12 @@ stringToValueStrings selectedValueEncoding valuesString =
else
case selectedValueEncoding of
CommaSeperated ->
Ok (String.split "," valuesString)
case config of
SingleSelectConfig _ _ _ ->
Ok [ valuesString ]

MultiSelectConfig _ _ _ ->
Ok (String.split "," valuesString)

JsonEncoded ->
percentDecode valuesString
Expand Down
Loading