Merge branch 'bug-fix-field-validation' into 'master'
Fix checkbox validator See merge request !40
This commit is contained in:
commit
6924ae0fb7
@ -388,7 +388,6 @@ $show_quick_help = $show['show'];
|
||||
|
||||
/* Select drop-down box */
|
||||
case 'select':
|
||||
|
||||
$cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
|
||||
|
||||
echo '<div class="form-group' . $cls . '"><label for="' . $v['name'] . '" class="col-sm-3 control-label">' . $v['name'] . ' ' . $v['req'] . '</label>
|
||||
@ -416,8 +415,11 @@ $show_quick_help = $show['show'];
|
||||
|
||||
/* Checkbox */
|
||||
case 'checkbox':
|
||||
|
||||
$cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
|
||||
|
||||
$validator = $v['req'] == '<span class="important">*</span>' ? 'data-checkbox="' . $k . '"' : '';
|
||||
$required_attribute = $validator == '' ? '' : ' data-error="' . $hesklang['this_field_is_required'] . '"';
|
||||
|
||||
echo '<div class="form-group' . $cls . '"><label class="col-sm-3 control-label">' . $v['name'] . ' ' . $v['req'] . '</label><div align="left" class="col-sm-9">';
|
||||
|
||||
foreach ($v['value']['checkbox_options'] as $option) {
|
||||
@ -427,7 +429,7 @@ $show_quick_help = $show['show'];
|
||||
$checked = '';
|
||||
}
|
||||
|
||||
echo '<div class="checkbox"><label><input type="checkbox" name="' . $k . '[]" value="' . $option . '" ' . $checked . $required_attribute . '> ' . $option . '</label></div>';
|
||||
echo '<div class="checkbox"><label><input ' . $validator . ' type="checkbox" name="' . $k . '[]" value="' . $option . '" ' . $checked . $required_attribute . '> ' . $option . '</label></div>';
|
||||
}
|
||||
echo '
|
||||
<div class="help-block with-errors"></div></div></div>';
|
||||
@ -783,6 +785,10 @@ $show_quick_help = $show['show'];
|
||||
/* Checkbox */
|
||||
case 'checkbox':
|
||||
$cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
|
||||
|
||||
$validator = $v['req'] == '<span class="important">*</span>' ? 'data-checkbox="' . $k . '"' : '';
|
||||
$required_attribute = $validator == '' ? '' : ' data-error="' . $hesklang['this_field_is_required'] . '"';
|
||||
|
||||
echo '<div class="form-group' . $cls . '"><label class="col-sm-3 control-label">' . $v['name'].' '.$v['req'] . '</label><div align="left" class="col-sm-9">';
|
||||
|
||||
foreach ($v['value']['checkbox_options'] as $option) {
|
||||
@ -792,7 +798,7 @@ $show_quick_help = $show['show'];
|
||||
$checked = '';
|
||||
}
|
||||
|
||||
echo '<div class="checkbox"><label><input type="checkbox" name="' . $k . '[]" value="' . $option . '" ' . $checked . ' ' . $required_attribute . '> ' . $option . '</label></div>';
|
||||
echo '<div class="checkbox"><label><input ' . $validator . ' type="checkbox" name="' . $k . '[]" value="' . $option . '" ' . $checked . $required_attribute .'> ' . $option . '</label></div>';
|
||||
}
|
||||
echo '<div class="help-block with-errors"></div></div></div>';
|
||||
break;
|
||||
|
@ -514,6 +514,8 @@ function print_add_ticket()
|
||||
/* Checkbox */
|
||||
case 'checkbox':
|
||||
$cls = in_array($k,$_SESSION['iserror']) ? 'isError' : '';
|
||||
$validator = $v['req'] == '<span class="important">*</span>' ? 'data-checkbox="' . $k . '"' : '';
|
||||
$required_attribute = $validator == '' ? '' : ' data-error="' . $hesklang['this_field_is_required'] . '"';
|
||||
echo '
|
||||
<div class="form-group '.$cls.'">
|
||||
<label for="'.$k.'" class="col-sm-3 control-label">'.$v['name'].' '.$v['req'].'</label>
|
||||
@ -530,7 +532,7 @@ function print_add_ticket()
|
||||
$checked = '';
|
||||
}
|
||||
|
||||
echo '<div class="checkbox"><label><input type="checkbox" name="'.$k.'[]" value="'.$option.'" '.$checked.' '.$required_attribute.'> '.$option.'</label></div>';
|
||||
echo '<div class="checkbox"><label><input ' . $validator . ' type="checkbox" name="'.$k.'[]" value="'.$option.'" '.$checked.' ' . $required_attribute . '> '.$option.'</label></div>';
|
||||
}
|
||||
echo '
|
||||
<div class="help-block with-errors"></div>
|
||||
@ -840,6 +842,8 @@ function print_add_ticket()
|
||||
/* Checkbox */
|
||||
case 'checkbox':
|
||||
$cls = in_array($k,$_SESSION['iserror']) ? 'isError' : '';
|
||||
$validator = $v['req'] == '<span class="important">*</span>' ? 'data-checkbox="' . $k . '"' : '';
|
||||
$required_attribute = $validator == '' ? '' : ' data-error="' . $hesklang['this_field_is_required'] . '"';
|
||||
echo '
|
||||
<div class="form-group '.$cls.'">
|
||||
<label for="'.$k.'" class="col-sm-3 control-label">'.$v['name'].' '.$v['req'].'</label>
|
||||
@ -856,7 +860,7 @@ function print_add_ticket()
|
||||
$checked = '';
|
||||
}
|
||||
|
||||
echo '<div class="checkbox"><label><input type="checkbox" name="'.$k.'[]" value="'.$option.'" '.$checked.' '.$required_attribute.'> '.$option.'</label></div>';
|
||||
echo '<div class="checkbox"><label><input ' . $validator . ' type="checkbox" name="'.$k.'[]" value="'.$option.'" '.$checked.' '.$required_attribute.'> '.$option.'</label></div>';
|
||||
}
|
||||
echo '
|
||||
<div class="help-block with-errors"></div>
|
||||
|
@ -16,24 +16,21 @@ function buildValidatorForTicketSubmission(formName, validationText) {
|
||||
$('form[name="' + formName + '"]').validator({
|
||||
custom: {
|
||||
checkbox: function($el) {
|
||||
var checkboxes = $('input[name="' + $el.attr('data-checkbox') + '[]"]');
|
||||
var name = $el.data('checkbox');
|
||||
var $checkboxes = $el.closest('form').find('input[name="' + name + '[]"]');
|
||||
|
||||
for (var checkbox in checkboxes) {
|
||||
if (checkboxes[checkbox].checked) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
multiselect: function($el) {
|
||||
var count = $('select[name="' + $el.attr('data-multiselect') + '[]"] :selected').length;
|
||||
return count > 0;
|
||||
return $checkboxes.is(':checked');
|
||||
}
|
||||
},
|
||||
errors: {
|
||||
checkbox: validationText,
|
||||
multiselect: validationText
|
||||
checkbox: validationText
|
||||
}
|
||||
}).on('change.bs.validator', '[data-checkbox]', function (e) {
|
||||
var $el = $(e.target);
|
||||
var name = $el.data('checkbox');
|
||||
var $checkboxes = $el.closest('form').find('input[name="' + name + '[]"]');
|
||||
|
||||
$checkboxes.not(':checked').trigger('input');
|
||||
});
|
||||
}
|
||||
|
||||
@ -41,18 +38,20 @@ function buildValidatorForPermissionTemplates(formId, validationText) {
|
||||
$('#' + formId).validator({
|
||||
custom: {
|
||||
checkbox: function($el) {
|
||||
var checkboxes = $('input[data-modal="new-' + $el.attr('data-checkbox') + '"]');
|
||||
var name = $el.data('checkbox');
|
||||
var $checkboxes = $el.closest('form').find('input[data-modal="new-' + name + '"]');
|
||||
|
||||
for (var checkbox in checkboxes) {
|
||||
if (checkboxes[checkbox].checked) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return $checkboxes.is(':checked');
|
||||
}
|
||||
},
|
||||
errors: {
|
||||
checkbox: validationText
|
||||
}
|
||||
}).on('change.bs.validator', '[data-modal]', function (e) {
|
||||
var $el = $(e.target);
|
||||
var name = $el.data('checkbox');
|
||||
var $checkboxes = $el.closest('form').find('input[data-modal="new-' + name + '"]');
|
||||
|
||||
$checkboxes.not(':checked').trigger('input');
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user