-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Required attribute #324
Comments
SimpleMDE hides the textarea, so that would be as expected. Instead of a |
I had this problem within Chrome too. It seems to prevent SimpleMDE syncing the content to the hidden textarea before the submit event happens. Works fine with the var simplemde = new SimpleMDE({
forceSync: true
}); |
@kraiz This won't work fully either, because if the content is empty, it'll result in the same error shown above. The problem is that the textarea is hidden. A JS approach is necessary. |
This still seems like a bit of an oversight to be honest. Instead of requiring users to add extra JS to validate a form, something should be done within the library to alleviate this. Especially if using a form factory like Symfony or Laravel, where you want this all to be done in code, in one place. |
@MatthewBooth there are hundreds of different ways to validate an input and display an error, whether before, during, or after submission. SimpleMDE's job is not to determine how to do that for the developer. |
Would it not be possible for SimpleMDE to remove any 'required' attribute from the text area and apply it to the markdown control? It's a while since I looked at this, perhaps it wouldn't work, but it seems like it could be workable. |
@chrisveness SimpleMDE would not know what to do if it was left blank, since an error message can be displayed in so many ways. It's up to the developer to not rely on the |
There is a very simple workaround for this problem. What I'm using mostly is HTML5 validation, so I rely on the browser to know how to display the validation message - and then, if I wanted to, but not necessarily, I could add some JS on top of it, but that's another question. So, the thing is, SimpleMDE creates its own textarea to keep the widget's value, and hides the original textarea. By simple removing the required attribute from the latter, and adding it to the former (which is displayed, but behind the actual editor box), the HTML5 validation works just fine.
It's not pretty, and it's just basic browser styles in there, but it works. Maybe you guys should consider adding this behavior by default to SimpleMDE, then let the developer choose what CSS rules they want in order to display the error messages in a more specific way. I hope this helps! |
@landart, yes, that's the sort of thing I had in mind. It could perhaps be generalised along the lines of (roughly)
@WesCossick I think this could make the library much more valuable: there's so many reasons to want to use native browser validation functions, not to try to reinvent the wheel with homegrown JS validation... Edit: it's a while since I was looking at this, I'm not sure what validation other than |
I'll look into applying the HTML attributes to the visible textarea. |
was having the same issue but i found a way around it, i just added the "novalidate" attribute to the form element and did my custom validation from the framework i was using and it worked |
We ran into this in the drupal wrapper module too. I'd say this is a major issue as ordinary users and integrators end up in a situation where they don not have any clue what happens, it's just "the form does not submit". (So is our downstream issue triaged.) I looked a bit into this.
So +1 for doing that (removing textarea 'required' and 'pattern') here in the library.
|
+1 |
Hi Wes. Great editor first of all! Did you ever get a chance to do this? |
Implement a JS, client-side validation workaround for a bug in the upstream editor library SimpleMDE which breaks HTML5 client-side validation when a wiki page is submitted. This allows native, client-side errors to appear if the text editor contents are empty. See upstream bugfix report: sparksuite/simplemde-markdown-editor#324 Signed-off-by: David Jimenez <[email protected]>
* fix: show client-side error if wiki page is empty Implement a JS, client-side validation workaround for a bug in the upstream editor library SimpleMDE which breaks HTML5 client-side validation when a wiki page is submitted. This allows native, client-side errors to appear if the text editor contents are empty. See upstream bugfix report: sparksuite/simplemde-markdown-editor#324 Signed-off-by: David Jimenez <[email protected]> Co-authored-by: Lauris BH <[email protected]>
* fix: show client-side error if wiki page is empty Implement a JS, client-side validation workaround for a bug in the upstream editor library SimpleMDE which breaks HTML5 client-side validation when a wiki page is submitted. This allows native, client-side errors to appear if the text editor contents are empty. See upstream bugfix report: sparksuite/simplemde-markdown-editor#324 Signed-off-by: David Jimenez <[email protected]> Co-authored-by: Lauris BH <[email protected]>
If I put a 'required' attribute on the textarea, I get an error
when I submit the form.
The text was updated successfully, but these errors were encountered: