@saltcorn/markup
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -17,3 +17,6 @@ const { | ||
module.exports = ({ options, context, action, stepName, layout }, csrfToken) => | ||
module.exports = ( | ||
{ options, context, action, stepName, layout, mode = "show" }, | ||
csrfToken | ||
) => | ||
div( | ||
@@ -37,4 +40,5 @@ script({ src: "/builder_bundle.js" }), | ||
${JSON.stringify(options)}, | ||
${JSON.stringify(layout || {})} | ||
${JSON.stringify(layout || {})}, | ||
${JSON.stringify(mode)} | ||
)`) | ||
); |
140
form.js
@@ -13,2 +13,3 @@ const { | ||
const { contract, is } = require("contractis"); | ||
const renderLayout = require("./layout"); | ||
@@ -172,27 +173,12 @@ const mkShowIf = sIf => | ||
const mkFormRowForField = ( | ||
v, | ||
errors, | ||
formStyle, | ||
labelCols, | ||
nameAdd = "" | ||
) => hdr => { | ||
const innerField = (v, errors, nameAdd = "") => hdr => { | ||
const name = hdr.name + nameAdd; | ||
const validClass = errors[name] ? "is-invalid" : ""; | ||
const errorFeedback = errors[name] | ||
? `<div class="invalid-feedback">${text(errors[name])}</div>` | ||
: ""; | ||
switch (hdr.input_type) { | ||
case "fromtype": | ||
return formRowWrap( | ||
return displayEdit( | ||
hdr, | ||
displayEdit( | ||
hdr, | ||
name, | ||
v && isdef(v[hdr.name]) ? v[hdr.name] : hdr.default, | ||
validClass | ||
), | ||
errorFeedback, | ||
formStyle, | ||
labelCols | ||
name, | ||
v && isdef(v[hdr.name]) ? v[hdr.name] : hdr.default, | ||
validClass | ||
); | ||
@@ -207,40 +193,23 @@ case "hidden": | ||
const opts = select_options(v, hdr); | ||
return formRowWrap( | ||
hdr, | ||
`<select class="form-control ${validClass} ${ | ||
hdr.class | ||
}" name="${text_attr(name)}" id="input${text_attr( | ||
name | ||
)}">${opts}</select>`, | ||
errorFeedback, | ||
formStyle, | ||
labelCols | ||
); | ||
return `<select class="form-control ${validClass} ${ | ||
hdr.class | ||
}" name="${text_attr(name)}" id="input${text_attr( | ||
name | ||
)}">${opts}</select>`; | ||
case "file": | ||
return formRowWrap( | ||
hdr, | ||
`${ | ||
v[hdr.name] ? text(v[hdr.name]) : "" | ||
}<input type="file" class="form-control-file ${validClass} ${ | ||
hdr.class | ||
}" name="${text_attr(name)}" id="input${text_attr(name)}">`, | ||
errorFeedback, | ||
formStyle, | ||
labelCols | ||
); | ||
return `${ | ||
v[hdr.name] ? text(v[hdr.name]) : "" | ||
}<input type="file" class="form-control-file ${validClass} ${ | ||
hdr.class | ||
}" name="${text_attr(name)}" id="input${text_attr(name)}">`; | ||
case "ordered_multi_select": | ||
const mopts = select_options(v, hdr); | ||
return formRowWrap( | ||
hdr, | ||
`<select class="form-control ${validClass} ${ | ||
hdr.class | ||
}" class="chosen-select" multiple name="${text_attr( | ||
name | ||
)}" id="input${text_attr( | ||
name | ||
)}">${mopts}</select><script>$(function(){$("#input${name}").chosen()})</script>`, | ||
errorFeedback, | ||
formStyle, | ||
labelCols | ||
); | ||
return `<select class="form-control ${validClass} ${ | ||
hdr.class | ||
}" class="chosen-select" multiple name="${text_attr( | ||
name | ||
)}" id="input${text_attr( | ||
name | ||
)}">${mopts}</select><script>$(function(){$("#input${name}").chosen()})</script>`; | ||
@@ -266,6 +235,44 @@ default: | ||
: the_input; | ||
return formRowWrap(hdr, inner, errorFeedback, formStyle, labelCols); | ||
return inner; | ||
} | ||
}; | ||
const mkFormRowForField = ( | ||
v, | ||
errors, | ||
formStyle, | ||
labelCols, | ||
nameAdd = "" | ||
) => hdr => { | ||
const name = hdr.name + nameAdd; | ||
const errorFeedback = errors[name] | ||
? `<div class="invalid-feedback">${text(errors[name])}</div>` | ||
: ""; | ||
if (hdr.input_type === "hidden") { | ||
return innerField(v, errors, nameAdd)(hdr); | ||
} else | ||
return formRowWrap( | ||
hdr, | ||
innerField(v, errors, nameAdd)(hdr), | ||
errorFeedback, | ||
formStyle, | ||
labelCols | ||
); | ||
}; | ||
const renderFormLayout = form => { | ||
const blockDispatch = { | ||
field(segment) { | ||
const field = form.fields.find(f => f.name === segment.field_name); | ||
return innerField(form.values, form.errors)(field); | ||
}, | ||
action({ action_name }) { | ||
return `<button type="submit" class="btn btn-primary">${text( | ||
form.submitLabel || "Save" | ||
)}</button>`; | ||
} | ||
}; | ||
return renderLayout({ blockDispatch, layout: form.layout }); | ||
}; | ||
const renderForm = (form, csrfToken) => { | ||
@@ -298,5 +305,24 @@ if (form.isStateForm) { | ||
); | ||
} else return mkForm(form, csrfToken, form.errors); | ||
} else if (form.layout) return mkFormWithLayout(form, csrfToken); | ||
else return mkForm(form, csrfToken, form.errors); | ||
}; | ||
const mkFormWithLayout = (form, csrfToken) => { | ||
const hasFile = form.fields.some(f => f.input_type === "file"); | ||
const csrfField = `<input type="hidden" name="_csrf" value="${csrfToken}">`; | ||
const top = `<form action="${form.action}" class="form-namespace ${ | ||
form.class | ||
}" method="${form.methodGET ? "get" : "post"}" ${ | ||
hasFile ? 'encType="multipart/form-data"' : "" | ||
}>`; | ||
const blurbp = form.blurb ? p(text(form.blurb)) : ""; | ||
const hiddens = form.fields | ||
.filter(f => f.input_type === "hidden") | ||
.map(f => innerField(form.values, form.errors)(f)) | ||
.join(""); | ||
return ( | ||
blurbp + top + csrfField + hiddens + renderFormLayout(form) + "</form>" | ||
); | ||
}; | ||
const mkForm = (form, csrfToken, errors = {}) => { | ||
@@ -303,0 +329,0 @@ const hasFile = form.fields.some(f => f.input_type === "file"); |
@@ -121,3 +121,3 @@ const { | ||
domReady(`$(window).scroll(function () { | ||
if ($(window).scrollTop() >= 50) { | ||
if ($(window).scrollTop() >= 10) { | ||
$('.navbar').css('background','white'); | ||
@@ -124,0 +124,0 @@ } else { |
{ | ||
"name": "@saltcorn/markup", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Markup for Saltcorn, open-source no-code platform", | ||
@@ -13,3 +13,3 @@ "homepage": "https://saltcorn.com", | ||
"dependencies": { | ||
"contractis": "^0.0.8", | ||
"contractis": "^0.0.9", | ||
"escape-html": "^1.0.3", | ||
@@ -28,3 +28,3 @@ "xss": "^1.0.6" | ||
}, | ||
"gitHead": "d4a0f3070191b628424af5325c229a0c82681de7" | ||
"gitHead": "2a088e28b3df98fb79b91d891ae0c2bff9811300" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29861
13
984
+ Addedcontractis@0.0.9(transitive)
- Removedcontractis@0.0.8(transitive)
Updatedcontractis@^0.0.9