EasyUI Forum
April 23, 2024, 03:10:16 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: tagbox required validation  (Read 7740 times)
samuel.fung
Newbie
*
Posts: 6


View Profile Email
« on: April 11, 2017, 07:28:39 PM »

This may be a duplicate of https://www.jeasyui.com/forum/index.php?topic=6400.0


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"});
« Last Edit: April 11, 2017, 07:30:11 PM by samuel.fung » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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>
Logged
samuel.fung
Newbie
*
Posts: 6


View Profile Email
« Reply #2 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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!