I've got checkbox with label that is generated by JSON, but I stucked with its validation. If the checkbox is required what is the right way of validating the checkbox with dojo?
<div data-tool-element="checkbox" data-tool-element-id="sampleCheckbox" data-tool-element-name="checkboxName" data-tool-element-label="Checkbox label content">
<label for="checkboxName" data-validation-checkbox="Checkbox is required.">
<input id="sampleCheckbox" name="checkboxName" type="checkbox"><span>Checkbox label content</span>
if (rule.checkbox) {
var input = query(element)[0].value
, checkboxMessage = domAttr.get(query(element)[0], 'data-validation-checkbox')
, checkboxValid = validate.check(input, "checked");
if (!checkboxValid) {
// Highlight the current element and it's label
domClass.add(element[0], 'errorBorder');
label.length > 0 && domClass.add(label[0], 'errorColor');
// Display the error message
domConstruct.create('div',
{
class: 'error',
innerHTML: checkboxMessage
}, query(element)[0], 'after');
}
Aucun commentaire:
Enregistrer un commentaire