Skip to Content
Menu
This question has been flagged
1 Reply
5919 Views

Hello,
How can we handle onchange JS event for our field:
I am using:


var ObsPlacentaWeightColor = FieldChar.extend({
        _render: function () {
            this._super.apply(this, arguments);
            if (this.value) {
                var value_arr = this.value;
                    if (value_arr < 300 || value_arr > 500) {
                        this.$el.css('color', 'red');
                    }
                }
        },

    });


But it is working on form saving, How can we handle this on onchange of our field.
Thanks.

Avatar
Discard
Best Answer

Hi,

Try the below code

$(document).ready(function() {
$('#THE FIELD ID').on('change', function() {
You can define onchanging function
});
});

Hope it helps

Avatar
Discard

This work but do not fulfill my purpose, requirement is, suppose there is an integer field and i want to change the color of text to red when it's greater by a value like 10 , but it effect on save when doing through widget.

But the code you have shared will not save the color.

Please suggest some solution on this. thank you