EasyUI Forum

General Category => Bug Report => Topic started by: samuel.fung on April 11, 2017, 07:28:39 PM



Title: tagbox required validation
Post by: samuel.fung on April 11, 2017, 07:28:39 PM
This may be a duplicate of https://www.jeasyui.com/forum/index.php?topic=6400.0

(https://www.jeasyui.com/forum/index.php?action=dlattach;topic=6615.0;attach=1461)
Despite a tag has been added, the "required" validation fails and blocks form submission.

Code:
<form id="f" method="post">
tags: <input id="t" name="tags" type="text"><br>
<input type="submit">
</form>

$("#t").tagbox({width: 200, required: true});
$("#f").form({url: "/tags"});


Title: Re: tagbox required validation
Post by: stworthy on April 11, 2017, 08:42:18 PM
The 'required' property validate the inputing value not the whole tagbox values. Please extend a new validation type to achieve your requirement.
Code:
<script type="text/javascript">
function getValidateValue(target){
var t = $(target);
if (t.hasClass('textbox-text')){
var vv = [];
t.parent().find('.textbox-value').each(function(){
vv.push($(this).val());
});
return vv;
} else {
return [$(target).val()];
}
}
$.extend($.fn.validatebox.defaults.rules, {
notEmpty: {
validator: function(value,param){
if ($(this).val()){return true;}
var vv = getValidateValue(this);
return vv.length>0;
},
message: 'The values can not be empty.'
}
});
$(function(){
$('#tb').tagbox({
required: false,
validType: 'notEmpty',
val: function(target){
return getValidateValue(target);
},
onRemoveTag: function(){
var target = this;
setTimeout(function(){
$(target).tagbox('validate');
},0)
},
inputEvents: $.extend({},$.fn.tagbox.defaults.inputEvents, {
blur: function(e){
var target = e.data.target;
$(target).tagbox('setText','');
}
})
});
})
</script>


Title: Re: tagbox required validation
Post by: samuel.fung on April 11, 2017, 09:25:52 PM
Thanks, it works. Please consider if it should be the default behaviour of required validation for tagbox.

"required" is to ensure something is submitted in the form. The "inputting value" are omitted in form submission, so there is no point in validating it.