Pages

Tuesday, December 11, 2012

How to setup a masked input for rich:calendar in RichFaces

In richfaces you can use jquery to set up masked inputs. First, you must download masked input plugin for the jQuery javascript library and reference it in some part of the page:

<h:outputScript name="js/jquery.maskedinput-1.3.min.js" target="head" />

Then, to mask some input field you should do:


<h:inputText id="date" value="#{bBean.date}" >
    <rich:jQuery selector="#date" query="mask('99/99/9999',{placeholder:'_'})" />
</h:inputText>

Unfortunely, the same doesn't work for rich:calendar. Richfaces automatically renders rich:calendar into an input field for the date text and a div for the calendar itself. The input field is generated with the id of the rich:calendar tag plus "inputDate" as a prefix: ie, if the calendar has id="dob", the generated input field will have the id="dobInputDate"; so one workaround could be:

<h:form id="someForm">
    ...

    <rich:calendar id="date" value="#{bBean.date}"
        enableManualInput="true" popup="true" showApplyButton="false" >
    </rich:calendar>
    <rich:jQuery selector="#someForm\:dateInputDate" query="mask('99/99/9999',{placeholder:'_'})" />
    ...
</h:form>

The attribute enableManualInput of the calendar should be set to true, otherwise it doesn't make sense to mask the input field.


20 comments:

  1. Thank you for this tutorial. That helps me a lot this day

    ReplyDelete
  2. I am very thankful to you that you have shared this information with us. Read more info about Low Cost Analog Layout Training. I got some different kind of knowledge from your web page, and it is really helpful for everyone. Thanks for share it.

    ReplyDelete
  3. E8F3253839Christopher5D2E3F4647October 11, 2024 at 7:18 PM

    2DC85C46C3
    whatsapp şov

    ReplyDelete
  4. 692099C4CAMalloryF67A7520D7November 26, 2024 at 6:48 PM

    57C4C3D7BD
    bayan beğeni

    ReplyDelete