question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting the input `value` directly with Javascript without using the `set()` method is not supported

See original GitHub issue

Expected behavior

To be able to fill an input field’s value with jQuery’s val function.

Actual behavior

Sadly, it does not work with AutoNumeric 4. And I can not call any trigger on the field to store (or even just parse) the value which was loaded to the input by the val function. I have several AutoNumeric fields and it would be a huge (and risky) work to refactor all value set from this:

$('#autonumeric_field1').val('60100').trigger('blur');

to this:

AutoNumeric.getAutoNumericElement($('#autonumeric_field1').get(0)).set(60100);

The first one was worked with AutoNumeric 1.9.

The main problem isn’t that it not formatting the value anymore but it doesn’t even store the value. If I set it with jQuery’s val, then I move the cursor to the field and move it out, the AutoNumeric restore the previous value to the field. It is a very, very dangerous behavior. The user can belive that the new value will be submitted but it isn’t if the AutoNumeric restore its value.

Steps to reproduce the problem

  1. Using autoNumeric 4.0.3 and the browser Chrome version 61.0.3163.100 (Official Build) (64-bit) on Windows 10,
  2. Set the field’s value with jQuery’s val function
  3. Move the cursor above the field then move it out.

Link to live example

JSFiddle

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
AlexandreBonneaucommented, Oct 18, 2017

For info, static set() and get*() functions are now available in v4.1.0-beta.12.

2reactions
AlexandreBonneaucommented, Oct 17, 2017

For info you can now use:

AutoNumeric.getAutoNumericElement('#theInput');

directly without having to first select the DOM element. This has been fixed in #514.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set Value of Input Using Javascript Function - Stack Overflow
I'm not using YUI, but my issue was that I had duplicate ID's on the page (was ... Changing the ID so it...
Read more >
Set the value of an input field in JavaScript - GeeksforGeeks
JavaScript setAttribute() Method: This method adds the specified attribute to an element and sets its specified value.
Read more >
<input type="text"> - HTML: HyperText Markup Language | MDN
A Boolean attribute which, if present, means this field cannot be edited by the user. Its value can, however, still be changed by...
Read more >
How to Get an Input's Value with JavaScript - Tabnine Academy
In the text input field example above, we used document.querySelector('input') to find the input field being modified. This query returns the first input....
Read more >
JavaScript - Bootstrap
Don't use data attributes from multiple plugins on the same element. For example, a button cannot both have a tooltip and toggle a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found