EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: jaimi on October 31, 2014, 06:42:01 AM



Title: maxlength for textbox
Post by: jaimi on October 31, 2014, 06:42:01 AM
Why is that not working:

$(function() {
 
  $("#HOM_NAME").textbox({
   required: true,
 
 }).prop('maxLength', 6);
 
 
})//function

So far, I didn't get any helping answer on my latest posts.
I still can not figure aut a solution to set the maximum length of a textfield.

Regards
Jaimi


Title: Re: maxlength for textbox
Post by: yamilbracho on November 01, 2014, 11:11:13 AM
Try

$(function() {
  $("#HOM_NAME").textbox({
   required: true,
 }).attr("maxlength", 6);
})//function

HTH,
Yamil


Title: Re: maxlength for textbox
Post by: jaimi on November 03, 2014, 10:39:56 PM
I tried this allready, doesn'r work.
Any other ideas?


Title: Re: maxlength for textbox
Post by: jarry on November 03, 2014, 10:52:44 PM
Please set the 'length' validation type to the textbox.
Code:
$("#HOM_NAME").textbox({
  required: true,
  validType: 'length[0,6]'
});


Title: Re: maxlength for textbox
Post by: jaimi on November 04, 2014, 05:52:50 AM
one can still put in more than 6 characters within the field. It is not valid then, but it is not the same as the maxlength attribute.

I solved it by creating my own textfield not using the jquery-textbox.

May you put this on the list for the next release.

Regards.
Jaimi


Title: Re: maxlength for textbox
Post by: jarry on November 04, 2014, 07:15:27 AM
If you really want to set the 'maxlength' attribute, you must get the inputing box first.
Code:
$("#HOM_NAME").textbox('textbox').attr('maxlength',6);


Title: Re: maxlength for textbox
Post by: Opan Mustopah on January 09, 2015, 03:12:03 AM
try this,

Code:
$.extend($.fn.textbox.defaults.rules, {
maxLength: {
validator: function(value, param){
return value.length <= param[0];
},
message: 'Maximum characters allowed only {0}'
}
});

it validate if value on input cannot more than param, and offcourse users cannot save data
hope it helps


Title: Re: maxlength for textbox
Post by: rkpunjal on February 05, 2015, 11:08:09 AM
This solution actually gets the textbox to behave as per the 'maxlength' standards (not allowing to key-in more characters)

Code:
$('#first-name').textbox();
$('#first-name').textbox('textbox').attr('maxlength', $('#first-name').attr("maxlength"));

or you can take a generic approach like this:

Code:
	$(function(){
$("input[class*='easyui-textbox'][maxlength][id]").each(function (i, elt) { // iterate all jeasyui textboxes having maxlength attribute and id attribute
// alert("found : " + elt.id );
$('#' + elt.id).textbox();
$('#' + elt.id).textbox('textbox').attr('maxlength', $('#' + elt.id).attr("maxlength"));

});
});


Title: Re: maxlength for textbox
Post by: azizkhani on March 24, 2015, 01:03:57 PM
This solution actually gets the textbox to behave as per the 'maxlength' standards (not allowing to key-in more characters)

Code:
$('#first-name').textbox();
$('#first-name').textbox('textbox').attr('maxlength', $('#first-name').attr("maxlength"));

or you can take a generic approach like this:

Code:
	$(function(){
$("input[class*='easyui-textbox'][maxlength][id]").each(function (i, elt) { // iterate all jeasyui textboxes having maxlength attribute and id attribute
// alert("found : " + elt.id );
$('#' + elt.id).textbox();
$('#' + elt.id).textbox('textbox').attr('maxlength', $('#' + elt.id).attr("maxlength"));

});
});


why just have id ????