Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Summernote and form validation

Posted on 2016-10-13
10
Medium Priority
?
612 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:amucinobluedot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 26

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:amucinobluedot
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 26

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
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 

Author Comment

by:amucinobluedot
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 26

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:amucinobluedot
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 26

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:amucinobluedot
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 26

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:amucinobluedot
ID: 41900935
Summernote was replaced, for the time being this won't be necessary. Thanks for the help.
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

730 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