简体   繁体   中英

Add custom message to knockout required validation

I have added a required validation to my observable. How can I change the message to something other than "This field is required."

self.Leaving = ko.observable(leaving).extend({
    required:   {
        onlyIf: function() { return self.Status() == 10; }
    }              
});
self.Leaving = ko.observable(leaving).extend({
    required:   {
        onlyIf: function() { return self.Status() == 10; },
        message: 'Custom message'
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM