简体   繁体   中英

weired beahviour when setting value of primefaces spinner using javascript

sorry for the vague title.

basically what I am trying to achieve is having 2 one for max and one for min value.

So my xhtml looks like follows:

<p:outputLabel for="max" value="Maximum Occurance: " />
<p:spinner id='max' min="1"  maxlength="3" size="3" value="#{ObjectDefinitionBean.max}" />

<p:outputLabel for="min" value="Minimum Occurance: " />
<p:spinner id='min' min="0"  maxlength="3" size="3" value="#{ObjectDefinitionBean.min}" />

I then addef ollowing javascript which basically checks if max>min and if not so sets the max value to the new min value, and the other eways round:

<script type="text/javascript" language="JavaScript">
//<![CDATA[
$("#ioDefCreation\\:max_input").change(function(){
    var min = parseInt($("#ioDefCreation\\:min_input").val());
    var max = parseInt($("#ioDefCreation\\:max_input").val());
    if(min>max){
        $("#ioDefCreation\\:min_input").val(max);
    }
});

$("#ioDefCreation\\:min_input").change(function(){
    var min = parseInt($("#ioDefCreation\\:min_input").val());
    var max = parseInt($("#ioDefCreation\\:max_input").val());
    if(max<min){
        $("#ioDefCreation\\:max_input").val(min);
    }
});
//]]>
</script>

So far everything wworks as intenden with the exception of a weired behaviour: lets say at the beginning both values are 0 I increase the minimum by 4 (by clicking the up arrow of the spinner) Now tha maximum shows 4 correctly. However if I now click the up arrow of the max it will display 1 (incrementing 1 from its initial value 0 instead of the value that was set using javascript). This is not limited to the case that the initial values are 0. it will reset the value of min and max to the values they where before they where altered via the javascript functions.

发生这种情况是因为在您的代码中max的最小值为1。当您使用javascript将其设置为0时,primefaces会接管控制并将其设置为最小指定值

<p:spinner id='max' !!!min="1"!!! maxlength="3" size="3" value="#{ObjectDefinitionBean.max}" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM