Enable/Disable one inputmask out of two in PrimeFaces
posted 11 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I am developing one form in jsf/primefaces. I have two inputText(inputMask) for e.g moble number and telephone number. I want to restrict the user to put only one of these two fields . That means if user starts putting value in mobile no. then telephone no. field should be disabled and if user starts putting value in telephone no. then mobile no. field should be disabled.
Please tell me how should I do this.
Please tell me how should I do this.
posted 11 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Howdy, welcome to the Ranch!
I've edited the title of your post, using all capitals gives the impression you're shouting so please KeepItDown (<- read this article)
You'll get the most help here if you ShowSomeEffort first. We are NotACodeMill so nobody is going to do it for you. So, show us what you've tried so far and tell us what particular thing you're having trouble with. Something along the lines of "I thought doing this thing here would work but it didn't. I expected this to happen but instead that happened" would be a good place to start.
I've edited the title of your post, using all capitals gives the impression you're shouting so please KeepItDown (<- read this article)
You'll get the most help here if you ShowSomeEffort first. We are NotACodeMill so nobody is going to do it for you. So, show us what you've tried so far and tell us what particular thing you're having trouble with. Something along the lines of "I thought doing this thing here would work but it didn't. I expected this to happen but instead that happened" would be a good place to start.
Tim Driven Development | Test until the fear goes away
posted 11 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
To actually disable a mutually-exclusive field in real time (when you are typing into the form) is something that you'd have to use Javascript for.
There are some things you'll have to take into account when doing this with JSF, however:
1. The actual field IDs that Javascript needs are the low-level element IDs, not the JSF high-level (template) IDs. So, instead of "homePhone" and "cellPhone", you'd have to code the Javascript to work with something like "myForm:homePhone" and "myForm:cellPhone". The exact names are determined by the IDs you give the naming containers (such as h:form), or will be randomly generated if you don't supply an id for the naming container (and it won't be predicatable, so give an explict id!)
2. Certain characteristics are set by JSF in ways that are not javascript-friendly, and the "disabled" attribute is one of them, so instead of declaring "disabled=true" on the View template, keep both fields enabled on the template and let the javascript handle the enable/disable.
You can attempt to use ajax instead of Javascript, but it would probably be trickier to do for stuff like this, and almost certainly less responsive. I prefer AJAX normally, because it's simpler, but perhaps not for this case.
There are some things you'll have to take into account when doing this with JSF, however:
1. The actual field IDs that Javascript needs are the low-level element IDs, not the JSF high-level (template) IDs. So, instead of "homePhone" and "cellPhone", you'd have to code the Javascript to work with something like "myForm:homePhone" and "myForm:cellPhone". The exact names are determined by the IDs you give the naming containers (such as h:form), or will be randomly generated if you don't supply an id for the naming container (and it won't be predicatable, so give an explict id!)
2. Certain characteristics are set by JSF in ways that are not javascript-friendly, and the "disabled" attribute is one of them, so instead of declaring "disabled=true" on the View template, keep both fields enabled on the template and let the javascript handle the enable/disable.
You can attempt to use ajax instead of Javascript, but it would probably be trickier to do for stuff like this, and almost certainly less responsive. I prefer AJAX normally, because it's simpler, but perhaps not for this case.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
| Goodbye moon men. Hello tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |









