admin管理员组文章数量:1291123
I use this plugin :
And I use this initialization :
AutoNumeric.multiple('.autonumeric-number', AutoNumericConfigDecimal);
AutoNumeric.multiple('.autonumeric-integer', AutoNumeric.getPredefinedOptions().integerPos);
And then, I have an Ajax call and I need to set the new value of my input. The problem is : I can't use .set()
method of the plugin because it requires to have a variable you got after initialisation.
Since I use multiple selectors, I can't have this variable.
For now, I tried to initialize again :
// element already has mask
<input id="element" class="autonumeric-integer" />
// after ajax call
var element = new AutoNumeric('#element', AutoNumericConfig);
element.set(value);
But it doubles what I write in the input, "2" bees "22".
Is it possible to use AutoNumeric functions using only the DOM element ? and not the variable you get after initialization ?
I use this plugin : https://github./autoNumeric/autoNumeric
And I use this initialization :
AutoNumeric.multiple('.autonumeric-number', AutoNumericConfigDecimal);
AutoNumeric.multiple('.autonumeric-integer', AutoNumeric.getPredefinedOptions().integerPos);
And then, I have an Ajax call and I need to set the new value of my input. The problem is : I can't use .set()
method of the plugin because it requires to have a variable you got after initialisation.
Since I use multiple selectors, I can't have this variable.
For now, I tried to initialize again :
// element already has mask
<input id="element" class="autonumeric-integer" />
// after ajax call
var element = new AutoNumeric('#element', AutoNumericConfig);
element.set(value);
But it doubles what I write in the input, "2" bees "22".
Is it possible to use AutoNumeric functions using only the DOM element ? and not the variable you get after initialization ?
Share Improve this question edited Nov 29, 2018 at 15:04 Gabriele Petrioli 196k34 gold badges271 silver badges328 bronze badges asked Nov 29, 2018 at 10:47 Vincent DecauxVincent Decaux 10.7k7 gold badges63 silver badges99 bronze badges3 Answers
Reset to default 8From the docs i see that there is a static method for finding the AutoNumeric
instance that handles an element, named getAutoNumericElement
So if you have the id
or a reference to the node you want you can pass it to this method and then you can call the set()
on it.
AutoNumeric.multiple('.autonumeric-integer', AutoNumeric.getPredefinedOptions().integerPos);
document.querySelector('button').addEventListener('click', function(){
// assuming you can target the elements based on id
const element = AutoNumeric.getAutoNumericElement('#element3')
element.set(13);
})
<script src="https://cdnjs.cloudflare./ajax/libs/autonumeric/4.1.0/autoNumeric.min.js"></script>
#element1: <input id="element1" class="autonumeric-integer" /><br/>
#element2: <input id="element2" class="autonumeric-integer" /><br/>
#element3: <input id="element3" class="autonumeric-integer" /><br/>
#element4: <input id="element4" class="autonumeric-integer" />
<button> update #element3 </button>
This one-liner should work for you as well.
AutoNumeric.set('#element','2');
you can use:
new AutoNumeric('#revenue', {
decimalPlaces: 0,
unformatOnSubmit: true
}); //
本文标签:
javascriptAutoNumericset a value after Ajax callStack Overflow
版权声明:本文标题:javascript - AutoNumeric - set a value after Ajax call - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:http://www.betaflare.com/web/1741524504a2383385.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论