locked
Validation output formatting RRS feed

  • Question

  • User-453926175 posted

    When using the following validation code:

    Validation.Add("Sales",
    Validator.Required("<i class='icon-warning-sign'></i>&nbsp;Required"),
    Validator.Decimal("<i class='icon-warning-sign'></i>&nbsp;Must be a number"));

    The validation for the Required formats the error correctly with the fontawesome warning sign and the text. The Decimal validation outputs the entire string between the quotes.

    How can I get the Decimal validation message to be the same as the Required validation?

    Thx,
    J Bishop

    Wednesday, June 4, 2014 1:24 PM

Answers

  • User-821857111 posted

    Try wrapping the Html.ValidationMessage() call in HTML.Raw()

    @Html.Raw(Html.ValidationMessage("Sales"))

    If that doesn't work you could use jQuery to apply the <I> tag.

    [EDIT]

    Had a chance to test my first suggestion. It doesn't work which leaves the jquery option:

    $(function () {
        var sales = $('span[data-valmsg-for="Sales"]')
        if (sales.hasClass('field-validation-error')) {
            sales.html('<i class="icon-warning-sign"></i> Must be a number');
        }
    });

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 4, 2014 1:41 PM

All replies

  • User-821857111 posted

    Try wrapping the Html.ValidationMessage() call in HTML.Raw()

    @Html.Raw(Html.ValidationMessage("Sales"))

    If that doesn't work you could use jQuery to apply the <I> tag.

    [EDIT]

    Had a chance to test my first suggestion. It doesn't work which leaves the jquery option:

    $(function () {
        var sales = $('span[data-valmsg-for="Sales"]')
        if (sales.hasClass('field-validation-error')) {
            sales.html('<i class="icon-warning-sign"></i> Must be a number');
        }
    });

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 4, 2014 1:41 PM
  • User-453926175 posted

    That did it Mike!

    Thx as always,
    J Bishop

    Wednesday, June 4, 2014 4:55 PM