Pregunta

Would you please guide me how to display validation message when I click 'Add New Color' and 'Save' button on empty textbox. After starting typing, validation starts showing message. Fiddler Link

self.SaveChanges = function (data, event) {
        var isValid = true;
        for (var prop in data) {
            if (data.hasOwnProperty(prop) && !data[prop].isValid()) {
                isValid = false;
                data[prop].error;
            }
        }
        if (isValid) {
            if (self.OperationMode() == 'A') {
                self.IntColors.push(data);
            }
            self.modalVisible(false);
        }


    };

Thanks in advance!

¿Fue útil?

Solución

I made this work as below. Thank you all for helping. Updated JSFiddler

self.SaveChanges = function (data, event) {
            var result = ko.validation.group(data, { deep: true });
            if (!data.isValid()) {
                result.showAllMessages(true);
            }
            else {
                self.modalVisible(false);
            }
        };
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top