A Function for showing the validation error message using Javascript

This function can be used to display validation messages in any form like the contact us page.

We can pass a message, type, and also the field: which determines under in which ‘div’ the message need to be displayed.

self.showMessage("Perfomance is required", "error") // function call

//function definition
showMessage: function(message, type, field) {
			var messageView = new MessageView({
				message: message,
				type: type
			});
			if (typeof field !== "undefined") {
				this.application.getLayout().$('[data-input="' + field + '"]').append(messageView.render().$el)
			} else {
				this.application.getLayout().$("form").append(messageView.render().$el)
			}
		}

Leave a comment

Your email address will not be published. Required fields are marked *