1

Has anybody successfully integrated Redactor editor with jQuery validation?

<textarea class="text-input textarea" rows="25" id="page_content" name="page_content"></textarea>

$("#add_cms").validate({
    rules: {
        page_content: "required"
        },
    messages: {
        page_content: "Content can't be empty!"
        }
});

@Sparky, I was struggling with it for a few hours, tried additional-methods too. But the method wasn't even getting invoked. I got frustrated and removed all those code. It was at that point that I asked the question here.

It seems that Redactor is rendering the textarea as display:none; so the jQuery validate isn't getting triggered.

Tony P V
  • 31
  • 5
  • That's a "yes/no" question. If you're really looking for a solution with code, then show your own attempt first. – Sparky Oct 28 '13 at 14:35
  • @Sparky Did you really have to take away 4 of my only 6 reputation points? I am pretty new here, give me a break. – Tony P V Oct 30 '13 at 11:10
  • I have no power to do any such thing. Also, comments is not the appropriate place to discuss or complain about your rep. – Sparky Oct 30 '13 at 13:54
  • Have you tried using [sync](http://imperavi.com/redactor/docs/api/#api-sync) in the [blurCallback](http://imperavi.com/redactor/docs/callbacks/#callback-blurCallback)? I think that will put the text into the textarea. – MForMarlon Oct 30 '13 at 23:21

1 Answers1

2

Quote OP:

It seems that Redactor is rendering the textarea as display:none; so the jQuery validate isn't getting triggered.

If that's all it is, you can simply enable that feature of the plugin.

By default, jQuery Validate will ignore all hidden fields. This can be reversed by setting the ignore option to [].

$("#add_cms").validate({
    ignore: [],    // <-- allows validation of all hidden fields
    rules: {
        page_content: "required"
    },
    messages: {
        page_content: "Content can't be empty!"
    }
});

See this answer: https://stackoverflow.com/a/8565769/594235

Community
  • 1
  • 1
Sparky
  • 98,165
  • 25
  • 199
  • 285