EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: lcsft on February 24, 2015, 03:08:23 AM



Title: numberbox issues [solved]
Post by: lcsft on February 24, 2015, 03:08:23 AM
Hello,

I am trying to get a numberbox tied to a checkbox, when the checkbox is unchecked I want to remove the required: true and disable the numberbox, but I can't get it to work.
Code:
<input type="checkbox" name="type_online" <?php if($type_online) echo 'checked="checked"'?> onchange="handleOnlineInput(this)" />

<input type="text" name="price_online" value="<?php echo $price_online?>" class="easyui-numberbox" data-options="width:'20%', precision:2, min:0, required: true" checked="checked" />

JS function:
function handleOnlineInput(el)
{
var form = jQuery(el).closest('form');
var price_online = jQuery(form).find('input[name="price_online"]:first');
if( jQuery(el).is(':checked') )
jQuery(price_online).numberbox({required: true, disabled: false});
else
jQuery(price_online).numberbox({required: false, disabled: true});
}

The jQuery(price_online).numberbox({required: true, disabled: false}); doesn't "eat" the attributes at all ... any ideas?

Thanks.


Title: Re: numberbox issues
Post by: stworthy on February 24, 2015, 04:25:59 AM
Please use the id selector instead.
Code:
<input type="text" id="price_online" name="price_online" value="<?php echo $price_online?>" class="easyui-numberbox" data-options="width:'20%', precision:2, min:0, required: true" checked="checked" />
Code:
var price_online = jQuery('#price_online');
//...


Title: Re: numberbox issues (solved)
Post by: lcsft on February 24, 2015, 05:53:23 AM
That works, thank you, but I can have the same form opened on multiple tabs, so I can't have the same id (and I don't want to use an automatic id generator), so is there any way around this? So far all other components (like grids, etc) worked fine with a jquery object, instead of an id.
Thx.

Edit: solved it,
instead of input[name="price_online"] I search for a .price_online class (so I add an extra class), like:
Code:
<input type="text" name="price_online" value="..."class="easyui-numberbox price_online" data-options="width:'20%', precision:2, min:0, required: true" checked="checked" />

that way it works, thank you again.