I use autoNumeric. Data that is added to the input
is cleared when you hover the input
element. Why are the values cleared? How to fix it? Demo
$('#thermForwardStream').focusout(function () {
var thermForwardStream = $('#thermForwardStream').val();
var thermBackStream = $('#thermBackStream').val();
if (thermBackStream == "70" ) {
$.ajax({
type: 'POST',
dataType: 'json',
data: { 'thermForwardStream': thermForwardStream, 'thermBackStream': thermBackStream },
url: '@Url.Action("GetDataAnnexY", "ThermLosses")',
success: function (data) {
$('#tempHeatExchangerOne').val(data.thermForwardStream);
$('#tempHeatExchangerTwo').val(data.thermBackStream);
}
});
}
});
const autoNumericOptions = {
allowDecimalPadding: "floats",
decimalCharacter: ",",
digitGroupSeparator: "",
emptyInputBehavior: "zero"
};
new AutoNumeric('#thermForwardStream', autoNumericOptions);
new AutoNumeric('#thermBackStream', autoNumericOptions);
new AutoNumeric('#tempHeatExchangerOne', autoNumericOptions);
new AutoNumeric('#tempHeatExchangerTwo', autoNumericOptions);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/autonumeric@4.1.0"></script>
<input class="form-control double" type="text" value="0" id="thermForwardStream" name="ThermForwardStream" required />
<input class="form-control double" type="text" value="70" id="thermBackStream" name="ThermBackStream" required />
<input class="form-control double" type="text" id="tempHeatExchangerOne" name="TempHeatExchangerOne" required />
<input class="form-control double" type="text" id="tempHeatExchangerTwo" name="TempHeatExchangerTwo" required />
Need to add property watchExternalChanges
.
Defines if the AutoNumeric element should watch external changes made without using .set()
const autoNumericOptions = {
allowDecimalPadding: "floats",
decimalCharacter: ",",
digitGroupSeparator: "",
emptyInputBehavior: "zero",
watchExternalChanges: true //!!!
};