LiveValidation plugin - HTML in failureMessage

104 Views Asked by At

I am using the LiveValidation plugin and was wondering of there is a way to add HTML in the span tags that show a valid or invalid message. I have the following:

var validatedObj = new LiveValidation('momlastname', { validMessage: ""});
validatedObj.add(Validate.Presence,{ failureMessage: "You need a name in this <strong>field</strong>"});

But when I test the code I get this:

Imgur

What am I missing?

2

There are 2 best solutions below

0
Noah Nathan On BEST ANSWER

Thanks @Danijel. I modified the function as follows:

createMessageSpan: function () {
            var span = document.createElement('span');
            span.innerHTML = this.message;
            return span;
        },
0
Danijel On

It is not implemented, failureMessage parameter is treated as string. Here is function that creates message ( source ), so you can change that:

createMessageSpan: function(){
    var span = document.createElement('span');
    var textNode = document.createTextNode(this.message);
    span.appendChild(textNode);
    return span;
},

It is also possible to override onValid and onInvalid default callbacks, and to impliment your own functionality. Check the official documentation for more info.