Good morning,
I'm struggling with adding inputs shorter than a mask to a list. The problem is that after entering the total length of the text consistent with the mask into inputMask, it is successful. If we enter a shorter one, it doesn't work.
What's funny is that when we type shorter text and press enter, the shorter texts are added without any problems. The problem occurs when we enter shorter text and press the addbutton button. Then the field is cleared.
I tried various things, such as replacing the mask
mask="***-***-***-**-***" with:
mask="?***-***-***-**-***"
I tried everything.
The validateMask="false" attribute also does not work in this case.
I read that you probably need to replace inputMask with a normal inputText and write a function in js that will imitate the mask in the field but this is hard to achieve.
My controller is also ok, it is only checking is the input is not empty.
Any ideas guys :(? I am sitting with that around the week.
Here is xhtml with inputMask and commandButton:
<p:column>
<p:inputMask id="teileNummer"
value="#{maZusTeilenummerController.teilenummerToAdd}"
styleClass="js-teilenummer-inputmask-full js-focused-when-visible-dialog"
converter="aeko.TeileNummerFullConverter"
autoClear="true"
mask="***-***-***-**-***"
validateMask="false">
</p:inputMask>
<p:keyFilter for="teileNummer" mask="alphanum" preventPaste="false" />
</p:column>
<p:column>
<p:commandButton id="addButton"
styleClass="button-right"
action="#{maZusTeilenummerController.addPosition(maPosController.filter.maNr, maPosController.filter.maPosNr, maZusTeilenummerController.teilenummerToAdd)}"
value="#{labels['button.hinzufuegen']}"
style="width:125px;"
ajax="true"
oncomplete="setPopupSize(); clearTeilenummerField(); "
update="zusTeilenummerMessages :zusTeilenummerForm:zusTeilenummerContent"
/>
</p:column>
And here is the controller:
public void addPosition(StringValueTO maNr, StringValueTO maPosNr, String teilenummerToAdd) {
// trim only the trailing whitespaces, as the preceding whitespace is required.
teilenummerToAdd = (StringUtils.stripEnd(teilenummerToAdd, null)).toUpperCase();
if(StringUtils.isNotBlank(teilenummerToAdd)){
teilenummerList.add(teilenummerToAdd);
teilenummerToAdd = "";
}
}
I tried adding a question mark as an optional character but it didn't work.
I also set the validateMask flag to false but after that only the enter button can add shorter teilenummers.