Skip to content

Commit

Permalink
bug: 77 select required
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Dec 14, 2016
1 parent 68e2664 commit 3a083ce
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/cli/cms/data/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function urlList(obj, tplPath, match, jsonPage) {
if(pathSource[1] != null) {
pathSource = pathSource[1].split('/')
pathSource.shift()
pathSource = '/' + path.join('/')
pathSource = '/' + pathSource.join('/')
}else {
pathSource = '/'
}
Expand Down
17 changes: 14 additions & 3 deletions src/cli/cms/editor/handlebars/printInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,24 @@ export function createInputSource(attributes, inputClass, params) {
lastValues = JSON.stringify(params.value).replace(/\'/g, '&quote;')
inputSource += `<select ${attributes} class="${inputClass}" last-values='${lastValues}'>`

if (!params.required) inputSource += '<option value=\'\'></option>'
// if (!params.required) inputSource += '<option value=\'\'></option>'
var options = ""
if(typeof params.source === 'object' && Object.prototype.toString.call(params.source) === '[object Array]') {
Array.prototype.forEach.call(params.source, (val) => {
inputSource += sourceOption(val, params)
options += sourceOption(val, params)
})
}else{
options += sourceOption(params.source, params)
}
else inputSource += sourceOption(params.source, params)

var defaultValueSelected = 'selected=selected'
if (options.indexOf('selected') > -1) {
defaultValueSelected = ""
}
if (params.required) inputSource += `<option value=\'\' value="" disabled ${defaultValueSelected}>Select ${params.desc.toLowerCase()}...</option>`
if (!params.required) inputSource += `<option value=\'\' value="" ${defaultValueSelected}></option>`
inputSource += options

inputSource += '</select>'
}
return inputSource
Expand Down
36 changes: 19 additions & 17 deletions src/cli/cms/templates/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,25 @@ export function addAbeDataAttrForHtmlAttributes(template, key) {
var text = template.replace(/<([A-Za-z]+)/g, '\nABE_SPLIT<$1')
let abeTagIntoAttribute = text.match(cmsData.regex.abeAsAttributePattern)

Array.prototype.forEach.call(abeTagIntoAttribute, (abeIntoTag) => {
let matchAbeTag = /({{abe.*?[\s\S].*?}})/g.exec(abeIntoTag)

if(matchAbeTag != null && matchAbeTag[1] != null) {
var toReplace = cmsTemplates.prepare.getAbeAttributeData(matchAbeTag[1], text, (abeIntoTag.split('=')[0]).trim(), abeIntoTag)

toReplace = toReplace.replace(
cmsData.regex.escapeTextToRegex(matchAbeTag[1]),
cmsTemplates.prepare.addHasAbeAttr(matchAbeTag[1])
)

text = text.replace(
cmsData.regex.escapeTextToRegex(abeIntoTag),
toReplace
)
}
})
if (abeTagIntoAttribute != null) {
Array.prototype.forEach.call(abeTagIntoAttribute, (abeIntoTag) => {
let matchAbeTag = /({{abe.*?[\s\S].*?}})/g.exec(abeIntoTag)

if(matchAbeTag != null && matchAbeTag[1] != null) {
var toReplace = cmsTemplates.prepare.getAbeAttributeData(matchAbeTag[1], text, (abeIntoTag.split('=')[0]).trim(), abeIntoTag)

toReplace = toReplace.replace(
cmsData.regex.escapeTextToRegex(matchAbeTag[1]),
cmsTemplates.prepare.addHasAbeAttr(matchAbeTag[1])
)

text = text.replace(
cmsData.regex.escapeTextToRegex(abeIntoTag),
toReplace
)
}
})
}
text = text.replace(/\nABE_SPLIT</g, '<')

return text
Expand Down

0 comments on commit 3a083ce

Please sign in to comment.