Skip to content

Commit

Permalink
fix: When a select input with max-length = 1 was created in precontri…
Browse files Browse the repository at this point in the history
…b, the result was improperly saved as an array
  • Loading branch information
gregorybesson committed Jan 11, 2017
1 parent 20c81de commit 5437b20
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
5 changes: 0 additions & 5 deletions src/cli/cms/editor/handlebars/sourceAttr.js
Expand Up @@ -18,11 +18,6 @@ export default function sourceAttr(obj, params) {
values = [params.value]
}

// if (params.key == "colors.single") {
// console.log('* * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
// console.log('params', params)
// }

Array.prototype.forEach.call(values, (pValue) => {
if (isSelected(pValue, displayName, str)) {
selected = 'selected'
Expand Down
2 changes: 1 addition & 1 deletion src/server/public/abejs/scripts/modules/EditorSave.js
Expand Up @@ -120,7 +120,7 @@ export default class EditorSave {
} else if (input.value.indexOf('{') > -1) {
value = JSON.parse(input.value)
} else {
value = input.value //.replace(/\"/g, '\"') + ''
value = input.value
}
setObjByString(this._json.data, dataId, value)
}
Expand Down
20 changes: 17 additions & 3 deletions src/server/public/abejs/scripts/modules/FormCreate.js
Expand Up @@ -117,8 +117,22 @@ export default class FormCreate {
var autocomplete = input.getAttribute('data-autocomplete') == 'true' ? true : false
var required = input.getAttribute('data-required') == 'true' ? true : false
var value = input.value

if (autocomplete) {
var maxlength = input.getAttribute('data-maxlength')

if (input.nodeName === 'SELECT' && maxlength != "1") {
var checked = input.querySelectorAll('option:checked')
value = []
Array.prototype.forEach.call(checked, (check) => {
if(check.value !== '') {
if(check.value.indexOf('{') > -1 || check.value.indexOf('[') > -1) {
value.push(JSON.parse(check.value))
}else {
value.push(check.value)
}
}
})
setObjByString(values, id, value);
} else if (autocomplete) {
var results = input.parentNode.querySelectorAll('.autocomplete-result')
values[id] = []
var mergedValues = []
Expand All @@ -142,7 +156,7 @@ export default class FormCreate {
if (value.indexOf('{') > -1) {
try {
var jsonValue = JSON.parse(value)
setObjByString(values, id, [jsonValue])
setObjByString(values, id, jsonValue)

if (required && values[id].length == 0) {
isValid = false
Expand Down

0 comments on commit 5437b20

Please sign in to comment.