Skip to content
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

Empty value on submit #1330

Closed
Looted opened this issue Sep 16, 2015 · 7 comments
Labels

Comments

@Looted
Copy link

@Looted Looted commented Sep 16, 2015

Summernote replaces empty content with <p><br></p> to help with focusing. The issue is however that I can't clear this value on submitting the form.
Even when I use jQuery submit event to clear both the textarea and the summernote code I still get those values posted to the server. It seems like Summernote still interferes and inserts <p><br></p> tags. I'd rather not sanitize those values server-side.
Did anyone managed to successfully clear the fields before submission?

@JacopoGobbi

This comment has been minimized.

Copy link

@JacopoGobbi JacopoGobbi commented Oct 2, 2015

👍
I think that if you switch to code view, you can delete everything from there.
Anyway I don't think this is a long term solution because it's not as user friendly as a WYSIWYG editor should be...

@hmert

This comment has been minimized.

Copy link

@hmert hmert commented Oct 28, 2015

Hi,
I've a workaround resolution

$('.summernote').each(function(){
      var summernote = $(this);
      $('form').on('submit',function(){
          if (summernote.summernote('isEmpty')) {
               summernote.val('');
          }else if(summernote.val()=='<p><br></p>'){
               summernote.val('');
          }
     });
 });
hmert added a commit to academic/vipa that referenced this issue Oct 28, 2015
@hackerwins

This comment has been minimized.

Copy link
Member

@hackerwins hackerwins commented Dec 27, 2015

@hmert 's way looks good to me.

@hmert

This comment has been minimized.

Copy link

@hmert hmert commented Dec 27, 2015

@hackerlose Do you want me to purpose a PR for this?

@ctf0

This comment has been minimized.

Copy link

@ctf0 ctf0 commented Jul 14, 2016

here is another fix so the backend validation kicks in

$('.some-form').submit(function() {
    if ($('.textarea').summernote('isEmpty')) {
        $('.textarea').val('');
    }
});

also note that anything other <p><br></p> in my case it was <p dir="auto"><br></p> wont trigger the isEmpty, so u should also add that to the condition like

$('.some-form').submit(function() {
    $('.textarea').each(function() {
        if (
            $(this).summernote('isEmpty') || 
            $(this).val() == '<p dir="auto"><br></p>' ||
            // this is needed in some rare cases, 
            // ex. validating inputs when updating an entry in laravel ""
           !$('.note-editable > p').html('<br>')
           ) {
            $(this).val('');
        }
    });
});

it took me like a couple of hours to find out the problem, checking the codeview is a good way to find the default value of the input

@ayacoda

This comment has been minimized.

Copy link

@ayacoda ayacoda commented Jan 24, 2019

This is how you do it guys in your CSS file, as simple as this:

.note-editor.note-frame .note-editing-area .note-editable {
font-size: 15px;
font-family: inherit;
}

@DiemenDesign

This comment has been minimized.

Copy link
Member

@DiemenDesign DiemenDesign commented Oct 4, 2019

This has been open for some time, I'm going to assume it's no longer an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.