1
votes

I put validation on name input field field you can see it when you click on addFields.I am having problem that validation message coming before click on Add Branch button because in addFields function i'm setting the value of name empty because if i don't do this click on edit and make changes and click add or cancel on it and after that click on addfields then it show the previous value in input fields. i want to show validation message on click of Add Branch and want input fields empty on click of addFields and with values on click of edit. How can i achieve these scenario together ?

here is link

 `http://jsfiddle.net/sohimohit/43zkoszu/13/` 
2
When you're initializing the name property (self.name("")), you have to tell Knockoutvalidation that it is unchanged. Try adding self.name.isModified(false); after you've changed the value to an empty string. - Marius Øvergård

2 Answers

1
votes

You can use showAllMessages(false) on your error object

http://jsfiddle.net/43zkoszu/16/

All though I must say that your method of doing this is a little strange. Normaly with MVVM you have a seperate model for this and create a new one each time you want to registger a new

0
votes

As @Marius has already said, you need use isModifed(false) for changed field. So, your code should be like this

self.AddField = function(){ 
        self.BranchId("");
        self.BranchId.isModified(false);

        self.name("");
        self.name.isModified(false);

        self.description("");
        self.description.isModified(false);

        // .... etc ..

        self.show(false);
        self.show.isModified(false);
        self.showFields(true);
        self.showFields.isModified(false);
    }

Also, please, notice you have comas (,) instead of semicolons (;) in your AddField code.