Max length validation message not appearing when testing inline edit

Max length validation message not appearing when testing inline edit

rdmrdm Posts: 194Questions: 55Answers: 4

I am setting up max string length validation and am encountering an unexpected message. Using this page as guidance, I applied this function.

"MaxLen(int max, ValidationOpts cfg=null) - Validate a string does not exceed a maximum length."

When I use this function and test it with an inline edit, I receive this message instead of the custom one: "Max 50 Chars".

This is my function.

.Field(new Field("FridayPlanning.SmallGroupNotes")
    .SetFormatter(Format.IfEmpty(null)) 
    .Validator(Validation.MaxLen(50,new ValidationOpts {Message="Max 50 Chars"}))   
    )

Am I using this function incorrectly?

This question has an accepted answers - jump to answer

Answers

  • rdmrdm Posts: 194Questions: 55Answers: 4

    The mystery deepens. It looks like I get that same system error when trying to edit any field because of a where condition I have:

    .Where(q => q.Where("WeekList.WeekDescription",weekstring, "IN",false))
    

    When I take that out, everything else works... but I need that there for the users. So now the issue becomes: how can I have that where condition in place without interfering with the ability to update a field.

  • rdmrdm Posts: 194Questions: 55Answers: 4
    Answer ✓

    I worked out the problem. It's a case of two independent things being correct in isolation conflicting with eachother when brought together.

    So if you're sending an array as a parameter in ajax, I discovered that before sending your ajax call, you need to first do some character replacements in the array. I had done this in the controller, but it appeared that it actually needs to be done on the client side.

    I'm pasting this below in case you're using .NET MVC and have a similar case as mine.


    // create and populate jQuery array from C# string[] in Model var weeks = []; @foreach (var item in Model.Weeks) { @:weeks.push("@item"); } // translate jQuery array into something the MVC Action can accept // the character replacements are needed because the "where" function in Editor requires it. var stringifiedWeeks = JSON.stringify(weeks).replace('[', '(').replace(']', ')').replace(/\"/g, '\''); // You can now make the ajax call. The validators will now work as expected. $('#example').DataTable({ dom: "Blfrtip", ajax: { url: "@Url.Action("JoinedTableTest")", data: { campus: "@Model.Campus", teacher: "@Model.Teacher", weeks: stringifiedWeeks }, type: "POST" },
  • allanallan Posts: 61,946Questions: 1Answers: 10,158 Site admin

    Thanks for the updates. Good to hear you've got it working now.

    Allan

  • rdmrdm Posts: 194Questions: 55Answers: 4

    @allan -- How do I mark my question as answered when I supplied the answer? The website is asking me to mark this question as answered.

  • allanallan Posts: 61,946Questions: 1Answers: 10,158 Site admin

    I've just done it. I need to modify the software at some point to allow that!

    Allan

This discussion has been closed.