Skip to content

Commit

Permalink
fix: bug json key
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Dec 19, 2016
1 parent 29f5b59 commit c35dadf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/cli/cms/editor/handlebars/sourceAttr.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ export function prepareDisplay(obj, str = null) {
var keys = getKeys(str)
Array.prototype.forEach.call(keys, (key) => {
var val = get(obj, key)

var pattern = new RegExp('{{'+key+'}}|'+key, 'g')
str = str.replace(pattern, val)
})
// console.log('params.value', params.value)

if (str == null) {
str = obj
Expand Down
4 changes: 3 additions & 1 deletion src/server/public/abejs/scripts/modules/EditorSave.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ export default class EditorSave {
}
}
})
}else if (input.value.indexOf('{') > -1) {
value = JSON.parse(input.value)
}else {
value = input.value.replace(/\"/g, '\"') + ''
value = input.value //.replace(/\"/g, '\"') + ''
}
setObjByString(this._json.data, dataId, value);
// this._json.data[dataId] = value
Expand Down
11 changes: 7 additions & 4 deletions src/server/public/abejs/scripts/modules/FormCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,22 @@ export default class FormCreate {
if (autocomplete) {
var results = input.parentNode.querySelectorAll('.autocomplete-result')
values[id] = []
var mergedValues = []
Array.prototype.forEach.call(results, function(result) {
var resultValue = result.getAttribute('value')
if (resultValue.indexOf('{') > -1) {
try {
var jsonValue = JSON.parse(resultValue)
setObjByString(values, id, jsonValue);
// values[id].push(jsonValue)
// setObjByString(values, id, jsonValue);
mergedValues.push(jsonValue)
}catch(e) {
// values[id].push(value)
// setObjByString(values, id, value);
mergedValues.push(value)
}
}
}.bind(this))
setObjByString(values, id, mergedValues);

if (required && values[id].length == 0) {
isValid = false
if(showErrors) parentNode.classList.add('has-error')
Expand Down Expand Up @@ -163,7 +167,6 @@ export default class FormCreate {
}
}
}.bind(this))

var slug = slugs[this._selectedTemplate]
var slugMatches = slug.match(/{{.*?}}/g)
if (slugMatches !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/views/partials/engine.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
{{abeImport 'create-form-template' @root.manager.config @root}}
{{abeImport 'create-form-tplname' @root.manager.config @root}}

<input class="form-control" type="hidden" name="oldFilePath" id="oldFilePath" value="{{@root.json.abe_meta.link}}" />
<input class="form-control" type="hidden" name="oldFilePath" id="oldFilePath" data-id="oldFilePath" value="{{@root.json.abe_meta.link}}" />
<div class="">
<div class="">
<button type="submit" class="btn btn-primary" date-abe-duplicate="true">duplicate</button>
Expand Down

0 comments on commit c35dadf

Please sign in to comment.