-
Notifications
You must be signed in to change notification settings - Fork 417
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
Browser autocomplete not working with autoNumeric #536
Comments
Hey @Norcoen , which version of AutoNumeric do you use? |
I'm using the latest stable release 4.0.3 from github |
I don't know how to provide you with a working example online. |
Yup. I'm having this issue too. I'm using autoNumeric v4.2.15. Here's my config: new AutoNumeric('.number-format', {
allowDecimalPadding: false,
caretPositionOnFocus: "start",
createLocalList: false,
digitGroupSeparator: " ",
emptyInputBehavior: "null",
maximumValue: "9999999999999",
minimumValue: "0",
unformatOnSubmit: true
}); |
Same here. window.config["invoice-amount-input"] = {
currencySymbol: "",
currencySymbolPlacement: "p",
decimalCharacter: ".",
digitGroupSeparator: ",",
minimumValue: "1.00",
negativePositiveSignPlacement: "r",
modifyValueOnWheel: false,
} |
and also with this config: new AutoNumeric('input.mask.money', {
decimalCharacter: ',',
digitGroupSeparator: '.',
unformatOnSubmit: true
}); |
Is someone working on this problem or has an idea what is causing this behavior? |
Well, the problem is that AutoNumeric needs to know when the browser(s) update the input in order to update the ...erm..., this is where you see how browsers still aren't always following a standard ; the autofill detection problem exists for a long time now, as you can see here and here, which some semi-working solution. This post from yesterday sums it up pretty well; existing solutions either have issues of their own, just do not work, or are very, very hacky :/ |
still no fix for this problem! 👎 |
You're welcome to send a pull request anytime, as stated by this issues' tags 😙 Or, you can lobby the browser makers to respect a standard there too, that would speed up the fix 😇 😉 (However since this issue is known by the React team for more than 4 years now, I doubt my one-man-only team will find a fix for that anytime soon unfortunately :() |
The 'input' event is triggered with an autocomplete input so this works for me: var anElement = new AutoNumeric(domElement);
if (! domElement.hasAttribute('autocomplete') || domElement.getAttribute('autocomplete') !== 'off') {
domElement.addEventListener("input", function(event) {
if (this.value.length > 0 && anElement.getNumericString().length == 0) {
anElement.set(this.value);
}
}, false);
} |
Not working in Firefox 60 ESR, as far as I can tell |
Maybe, but works fine with Firefox 64, Chrome 7, Opera 57 and Edge, It's a solution for those who use recent browsers |
Well, with Firefox The bug is still present in Chromium 72 though, and the workaround form @eureka2 indeed works as stated. |
@AlexandreBonneau : do you plan to include this workaround in AutoNumeric.js ? |
@eureka2 I´ll consider it |
Thanks @eureka2 , that helped. I had to modify your code a little to make it work with AutoNumeric.multiple(). This code uses a bit of jQuery but that's not strictly necessary of course. var $domElements = $('.my-selector');
new AutoNumeric.multiple($domElements.toArray());
$domElements.on('input', function () {
var anElement = AutoNumeric.getAutoNumericElement(this);
if (anElement && this.value.length > 0 && anElement.getNumericString().length === 0) {
anElement.set(this.value);
}
}); |
Unfortunately, the @marcvangend We tried using your solution as a debounced callback for We didn't go through the extra work of detecting if the |
Thank you this work perfect for me. |
Thanks @eureka2. var $domElements = $('.autonumeric');
new AutoNumeric.multiple($domElements.toArray());
$domElements.on('input', function () {
var anElement = AutoNumeric.getAutoNumericElement(this);
if (anElement && this.value.length > 0) {
anElement.set(this.value, null, true);
}
}); Note that this means it should now be easy to fix autoNumeric itself by adding this listener in the code, right ? |
We are using the latest autonumeric and this seems to work for us in all browsers including Chrome. var $domElements = $('.autonumeric');
new AutoNumeric.multiple($domElements.toArray());
$domElements.on('blur', function(e) {
var element = AutoNumeric.getAutoNumericElement(this);
if (element && this.value && this.value.length > 0) {
element.set(this.value, null, true);
}
}); |
Any plans for this to be incorporated into autonumeric.js? My test results: This did not work for me because "this.value" was empty (solution recommended by @dclause, @melloware) var $domElements = $('.autonumeric');
new AutoNumeric.multiple($domElements.toArray());
$domElements.on('blur', function(e) {
var element = AutoNumeric.getAutoNumericElement(this);
if (element && this.value && this.value.length > 0) {
element.set(this.value, null, true);
}
}); This did work. I didn't notice any side effects like @afzafri mentioned. $domElements.on('input', function () {
var anElement = AutoNumeric.getAutoNumericElement(this);
if (anElement && this.value.length > 0 && anElement.getNumericString().length === 0) {
anElement.set(this.value);
}
}); |
@melloware Thanks for the fix, it works but with a small modification, I had to remove the line that initializes all autonumeric elements:
With this line removed, I take care of the initialization in local scripts (with different configurations for different elements), and then include this fix site-wide, and it works perfectly! |
Expected behavior
If you input a value like "55,55" into an element and submit the form, the browser displays a dropdown select the next time you visit the page and double click the same element.
When you select the previously entered value "55,55" it is pasted into the element.
Actual behavior
The value is pasted, but as soon as the focus is lost on the input element, autoNumeric deletes the value
Steps to reproduce the problem
Use any element with autoNumeric as described above
The text was updated successfully, but these errors were encountered: