Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Summernote and form validation

Posted on 2016-10-13
10
Medium Priority
?
825 Views
Last Modified: 2016-11-24
I am trying to add code to validate summernote and other fields in a form. I added code to validate summernote field and it seems to work fine, but then the rest of the validation script doesn't work. below is my code. Not sure how to clean it up so that all fields are validated.

  <script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$(document).ready(function() {
	
	$('#form1')
        .formValidation({
            framework: 'bootstrap',
            excluded: [':disabled'],
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                title: {
                    validators: {
                        notEmpty: {
                            message: 'The title is required and cannot be empty'
                        }
                    }
                },
                summernote: {
                    validators: {
                        callback: {
                            message: 'The content is required and cannot be empty',
                            callback: function(value, validator, $field) {
                                var code = $('[name="summernote"]').summernote('code');
                                // <p><br></p> is code generated by Summernote for empty content
                                return (code !== '' && code !== '<p><br></p>');
                            }
                        }
                    }
                }
            }
        })
        .find('[name="summernote"]')
            .summernote({
                height: 400
            })
            .on('summernote.change', function(customEvent, contents, $editable) {
                // Revalidate the content when its value is changed by Summernote
                $('#form1').formValidation('revalidateField', 'summernote');
            })
            .end();


    $('#form1').formValidation({
        framework: 'bootstrap',
        icon: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
           			
						subject: {
                validators: {
                    notEmpty: {
                        message: 'Please enter a short description'
                    },
                }
            },
			getForm: {
                validators: {
                    notEmpty: {
                        message: 'Please make a selection'
                    },
                }
            },
			
						bug_type: {
                validators: {
                    notEmpty: {
                        message: 'Please make a selection'
                    },
                }
            },
			
				browser: {
                validators: {
                    notEmpty: {
                        message: 'Please select a browser'
                    },
                }
            },
			
		
					
  }
		
    });
});
});//]]>  

</script> 

Open in new window

0
Comment
Question by:Aleks
  • 5
  • 5
10 Comments
 
LVL 27

Expert Comment

by:lenamtl
ID: 41843611
Hi, check with chrome dev tool (right click / inspect) to see if you have any JS  error in the console.

Also add server side validation.
0
 

Author Comment

by:Aleks
ID: 41847607
I actually don't get any errors because the validation for the summer note works, but the rest of the validation doesn't, it does not validate those other fields

Here is the code I put together for the form:

The first part of the validation works fine, the summer note validation doesn't work at all, no errors though. Simply as if there was no validation for that field.

 <script>
$(document).ready(function(){

$('.summernote').summernote( { focus: true } );

       });
       			
    </script>
   <script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$(document).ready(function() {
	



    $('#form1').formValidation({
        framework: 'bootstrap',
        icon: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
           			
						subject: {
                validators: {
                    notEmpty: {
                        message: 'Please enter a short description'
                    },
                }
            },
			getForm: {
                validators: {
                    notEmpty: {
                        message: 'Please make a selection'
                    },
                }
            },
			
						bug_type: {
                validators: {
                    notEmpty: {
                        message: 'Please make a selection'
                    },
                }
            },
			
				browser: {
                validators: {
                    notEmpty: {
                        message: 'Please select a browser'
                    },
                }
            },
			
		
					
  }
		
    });
});
});//]]>  

</script> 



  <script>
    $(function() { // RUN ON PAGE LOAD
      // HIDE ALL
      $('[class^="getForm"]').hide(); //NOTE WILD CARD

      $('select#getForm').on('change', function() {
          $('[class^="getForm"]').hide(); //HIDE ALL
          // NOW SHOW ONLY THE SELECTED
          var formName = $(this).val(); // VALUE OF SELECTED
          $('.' + formName).show();  // SHOW IT

      });

  });
  </script>
  
  <script>
    $(".chosen-select").chosen({
    disable_search_threshold: 10,
    no_results_text: "Oops, the form is not in the list!",
    width: "95%",
	inherit_select_classes: "false"
	
  });
  </script>
  
<script>
$(document).ready(function() {
    $('#form')
        .formValidation({
            framework: 'bootstrap',
            excluded: [':disabled'],
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {

                summernote: {
                    validators: {
                        callback: {
                            message: 'The content is required and cannot be empty',
                            callback: function(value, validator, $field) {
                                var code = $('[name="summernote"]').summernote('code');
                                // <p><br></p> is code generated by Summernote for empty content
                                return (code !== '' && code !== '<p><br></p>');
                            }
                        }
                    }
                }
            }
        })
        .find('[name="summernote"]')
            .summernote({
                height: 400
            })
            .on('summernote.change', function(customEvent, contents, $editable) {
                // Revalidate the content when its value is changed by Summernote
                $('#summernoteForm').formValidation('revalidateField', 'summernote');
            })
            .end();
});
</script>

Open in new window


Any ideas ?
0
 
LVL 27

Assisted Solution

by:lenamtl
lenamtl earned 2000 total points
ID: 41848766
For the part of your js that start like this
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$(document).ready(function() {

Open in new window


have you tried to use only one at the time
$(document).ready(function() {
or
$(window).load(function(){
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Aleks
ID: 41849964
If I delete either I get syntax errors. Also, that scripts works fine, is the summer note script that doesn't
0
 
LVL 27

Expert Comment

by:lenamtl
ID: 41849993
Why are you using two set of validation? try to regroup into one set.
Do you have a live link or codepen so we can test it?
0
 

Author Comment

by:Aleks
ID: 41850204
I tried to put it in one set of validation but I was unable to, if you can help do this that would be great :)
I will try and setup a test site for you to see.
0
 
LVL 27

Assisted Solution

by:lenamtl
lenamtl earned 2000 total points
ID: 41850727
Could you try this:
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
	$(document).ready(function() {
	
	$('#form1').formValidation({
            framework: 'bootstrap',
            excluded: [':disabled'],
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                title: {
                    validators: {
                        notEmpty: {
                            message: 'The title is required and cannot be empty'
                        }
                    }
                },
                summernote: {
                    validators: {
                        callback: {
                            message: 'The content is required and cannot be empty',
                            callback: function(value, validator, $field) {
                                var code = $('[name="summernote"]').summernote('code');
                                // <p><br></p> is code generated by Summernote for empty content
                                return (code !== '' && code !== '<p><br></p>');
                            }
                        }
                    }
                }
				
				subject: {
					validators: {
						notEmpty: {
							message: 'Please enter a short description'
						},
					}
				},
				
				getForm: {
					validators: {
						notEmpty: {
							message: 'Please make a selection'
						},
					}
				},
			
				bug_type: {
					validators: {
						notEmpty: {
							message: 'Please make a selection'
						},
					}
				},
			
				browser: {
					validators: {
						notEmpty: {
							message: 'Please select a browser'
						},
					}
				}

            }
        })
        .find('[name="summernote"]')
            .summernote({
                height: 400
            })
            .on('summernote.change', function(customEvent, contents, $editable) {
                // Revalidate the content when its value is changed by Summernote
                $('#form1').formValidation('revalidateField', 'summernote');
            })
            .end();

});
});//]]>  

</script> 

Open in new window

or this
 <script type='text/javascript'>//<![CDATA[ 

	$(document).ready(function() {
	
	$('#form1').formValidation({
            framework: 'bootstrap',
            excluded: [':disabled'],
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                title: {
                    validators: {
                        notEmpty: {
                            message: 'The title is required and cannot be empty'
                        }
                    }
                },
                summernote: {
                    validators: {
                        callback: {
                            message: 'The content is required and cannot be empty',
                            callback: function(value, validator, $field) {
                                var code = $('[name="summernote"]').summernote('code');
                                // <p><br></p> is code generated by Summernote for empty content
                                return (code !== '' && code !== '<p><br></p>');
                            }
                        }
                    }
                }
				
				subject: {
					validators: {
						notEmpty: {
							message: 'Please enter a short description'
						},
					}
				},
				
				getForm: {
					validators: {
						notEmpty: {
							message: 'Please make a selection'
						},
					}
				},
			
				bug_type: {
					validators: {
						notEmpty: {
							message: 'Please make a selection'
						},
					}
				},
			
				browser: {
					validators: {
						notEmpty: {
							message: 'Please select a browser'
						},
					}
				}

            }
        })
        .find('[name="summernote"]')
            .summernote({
                height: 400
            })
            .on('summernote.change', function(customEvent, contents, $editable) {
                // Revalidate the content when its value is changed by Summernote
                $('#form1').formValidation('revalidateField', 'summernote');
            })
            .end();


});//]]>  

</script> 

Open in new window

0
 

Author Comment

by:Aleks
ID: 41850864
Neither worked. the summer note field stopped working and  also it only validated the summer note and none of the other fields  :$
0
 
LVL 27

Accepted Solution

by:
lenamtl earned 2000 total points
ID: 41850879
Please set up a test site so I can check the whole code including the form
The code I gave you is based on the code you provide in your question.

The latest post  (2016-10-17 at 22:12:06) you added extra code like this don't remove it

 <script>
$(document).ready(function(){

$('.summernote').summernote( { focus: true } );

       });
       			
    </script>

Open in new window

0
 

Author Closing Comment

by:Aleks
ID: 41900935
Summernote was replaced, for the time being this won't be necessary. Thanks for the help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question