New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InputNumber: wrong selection after ajax #9458
Comments
Not sure I want to fix this because this is a race between your AJAX update and the tab key and AutoNumeric but here is a nice little workaround using AJAX <h:form>
<p:inputNumber id="value" value="#{testView.number}">
<p:ajax update="value3" listener="#{testView.calc()}"/>
</p:inputNumber>
<p:inputNumber id="value2" value="#{testView.number2}">
<p:ajax update="value3" listener="#{testView.calc()}" oncomplete="PF('wgtValue3').input.select();"/>
</p:inputNumber>
<p:inputNumber id="value3" widgetVar="wgtValue3" value="#{testView.number3}"/>
</h:form> |
I marked this 3rd party as I actually believe its AutoNumeric that automatically selects all the text when you tab in. so its selecting the range of 3 then your AJAX update wipes it out and its still only has the range select of 3 |
Hi @melloware , is there some way of inject some autonumeric configuration through Primefaces or some JS file?
|
Let me take a look I think I can give you something! |
OK here is a working project I added this monkeyPatch to if (PrimeFaces.widget.InputNumber) {
PrimeFaces.widget.InputNumber.prototype.init = function(cfg) {
PrimeFaces.widget.BaseWidget.prototype.init.call(this, cfg);
this.input = $(this.jqId + '_input');
this.hiddenInput = $(this.jqId + '_hinput');
this.plugOptArray = cfg.pluginOptions;
this.valueToRender = cfg.valueToRender;
this.disabled = cfg.disabled;
// GitHub #8125 minValue>0 shows js warning and quirky behavior
if (this.cfg.minimumValue > 0.0000001 || this.cfg.maximumValue < 0) {
this.cfg.overrideMinMaxLimits = 'invalid';
}
//bind events if not disabled
if (this.disabled) {
this.input.attr("disabled", "disabled");
this.input.addClass("ui-state-disabled");
this.hiddenInput.attr("disabled", "disabled");
}
//Visual effects
PrimeFaces.skinInput(this.input);
this.wrapEvents();
this.bindInputEvents();
this.cfg.caretPositionOnFocus = AutoNumeric.options.caretPositionOnFocus.start;
this.cfg.selectOnFocus = AutoNumeric.options.selectOnFocus.doNotSelect;
this.autonumeric = new AutoNumeric(this.jqId + '_input', this.cfg);
if (this.valueToRender !== "") {
//set the value to the input the plugin will format it.
this.autonumeric.set(this.valueToRender);
// GitHub #6940 blur firing too many change events
this.autonumeric.rawValueOnFocus = this.valueToRender;
}
this.setValueToHiddenInput(this.getValue());
//pfs metadata
this.input.data(PrimeFaces.CLIENT_ID_DATA, this.id);
this.hiddenInput.data(PrimeFaces.CLIENT_ID_DATA, this.id);
}
} |
I think I need to add these two props to the component for the future if someone else wants to set these. |
in 13.0 you will be able to do this |
Describe the bug
If the inputNumber is updated by an ajax call before getting focus, and the value is bigger than the old value,
just part of the new value is selected
This image shows what happens
This other shows what shoul happen
Reproducer
primefaces-test-master.zip
1 - open http://localhost:8080/primefaces-test/
2 - type 10 on first inputNumber
3 - tab and type 1000 on the second inputNumber
4 - tab again, the third input will receive the value 10000.00 but only the first three digits will be selected instead of the whole value.
Expected behavior
the whole value should be selected.
PrimeFaces edition
Community
PrimeFaces version
12.0.0
Theme
No response
JSF implementation
Mojarra
JSF version
any
Java version
11
Browser(s)
any
The text was updated successfully, but these errors were encountered: