Search code examples
jsfprimefaceskeyfilter

Disable / Enable primefaces keyFilter


I have an keyFilter to my p:inputMask i want to disable and enable the keyFilter

<div class="col-sm-6 #{(newDesWeb eq '_')?'input-group' : ''} errorCible"  >
                <p:inputMask  inputStyleClass="#{(newDesWeb eq '_')? 'selectfile' : 'form-control lg200 input-sm'}  errorCible"
                    id="zoneResidenceAssure" styleClass="#{(newDesWeb eq '_')? 'ng-pristine ng-invalid ng-touched' : ''}  errorCible"
                    style="width: 100%"
                    value="#{devisPresBean.currentAssureDevisBean.adresseActuelle.zipCode}" maxlength="#{msg['form.control.input.codepostal.maxlength']}">
                    <c:passThroughAttribute name="fieldId" value="LIBDEVzoneResidenceAssure" />
                    <c:ajax onevent="displayAjaxSatus" event="change" execute="@this" render="@this" />
                </p:inputMask>
                <p:keyFilter regEx="/[0-9_]/i" for="zoneResidenceAssure" />
                <bpsi:message for="zoneResidenceAssure" />
                 
            </div>

I want with a condition disable the p:keyFilter


Solution

  • You can do this in 3 way:

    1. use rendered on <p:keyFilter regEx="/[0-9_]/i" for="zoneResidenceAssure" rendered="#{backing.condition()}"/> but then ypu need to update the container of keyFilter be it a form or a panel on the condition change.

    2. use a dynamic regex like <p:keyFilter regEx="#{backing.regex()}" for="zoneResidenceAssure" /> and update the keyFilter on every condition change, returning actual pattern if you want it enabled or empty string to disable it.

    3. use testFunction on the keyFilter instead of regEx and implement the condition in JavaScript as a test function.