CKEditor does not recognize attribute required

5

I'm using CKEditor to create pages that can contain forms (in other words, forms can be inserted into content being edited , because I'm using the full package ). I would like to be able to use the required attribute in some fields of the forms being edited (it is supported by most modern browsers , and in my case a solution via JavaScript would be at least inconvenient 1 ), but CKEditor not only does not offer this option as well - while trying edit the font directly - remove this attribute if I try to put it "by force".

To make matters worse, CKEditor does not allow you to add classes to% s of% s, also removing them if I put them right in the source (is there any way to disable this?). All I have left is to do even bigger games to get where I want to (viable, however, you do not have to suggest this in response, because I already have some media in mind).

Is there any way to "force" CKEditor to accept this attribute? Even for this I have to disable other validations that this tool does? Or is this something specific to input , and each browser will do it your way with no possibility of customization?

1. Clarifying: it is not a problem for me to put a "generic" JavaScript that also acts on any page created, the problem is having to create a specific JS code for each form that is created (as this is a the customer! ).

    
asked by anonymous 10.04.2015 / 18:41

2 answers

4

The setting extraAllowedContent lets you zoom in the 1 filters that determine what is or is not accepted in the markup handled by CKEditor. To allow the required attribute to input s and textarea s, for example, you can use this setting:

CKEDITOR.config.extraAllowedContent = 'input[required];' + 
                                      'textarea[required];';

In case I used a global configuration, but could also do it in a specific editor.

1. These filters are the same quoted by Michel Simões in his response (which pointed me in the right direction to get this solution ).

    
13.04.2017 / 14:59
3

You can use the filter.check property to check for text, for example to check for an image in the text: filter.check ('img [alt]'); // - > true  or if you want you can use filter.check ('', true, true); // - > true that it will return false if the field is blank.

    
15.04.2015 / 14:07