Knockout Validation Only If a specific button is pressed

后端 未结 1 573
孤独总比滥情好
孤独总比滥情好 2021-01-24 18:49

https://github.com/ericmbarnard/Knockout-Validation/wiki/Native-Rules

I am using the knockout validation on my MCV3 page. The situation I have is that I have two buttons

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-24 19:32

    The onlyIf option could work here:

    FirstName: ko.observable().extend({ 
        required: {
            params: true,
            onlyIf: function(){ return someFlagIsTrue; }
        }
    

    You would need to set the someFlagIsTrue from your click event or other means.

    0 讨论(0)
提交回复
热议问题