Failed to check TinyMCE in asp mvc

I have a form that uses unobtrusive validation. I recently changed the text area to use a tiny mce, and now the check does not work.
I tried using the solution from here , but nothing happens.

$('#form input[type=submit]').click(function () {

Never executed. Here is what I have:

@using (Html.BeginForm("Create", "UserAd", FormMethod.Post))
{
...
@Html.TextAreaFor(x => x.Description, new { id = "description" })        
...
<input type="submit" value="Create"/>
...

This is the JS code:

$(document).ready(function () {

        tinyMCE.init({
            mode: "textareas",
            theme: "advanced",
            skin: "o2k7",
            height: "250",
            plugins: "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",


            theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist",
            theme_advanced_buttons2: "",
            theme_advanced_buttons3: "",
            theme_advanced_buttons4: "",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_resizing: false
        });

        function toggleEditor(id) {
            if (!tinyMCE.get(id)) {
                tinyMCE.execCommand('mceAddControl', false, id);
            }
            else {
                tinyMCE.execCommand('mceRemoveControl', false, id);
            }
        }


        // new
        $(function () {
            var tinymce = $('#Description');

            tinymce.tinymce({
                setup: function (e) {
                    e.onInit.add(function () {
                        tinymce.css({
                            position: 'absolute',
                            height: 0,
                            width: 0,
                            top: -100
                        }).show();
                    });
                }
            });

            $('#form input[type=submit]').click(function () {
                alert('ss');
                tinyMCE.triggerSave();
            });
        });
        // makes form field highlighting work with bootstrap css
        $.validator.setDefaults({
            highlight: function (element, errorClass, validClass) {
                $(element).closest('.control-group').addClass('error');
            },
            unhighlight: function (element, errorClass, validClass) {
                $(element).closest('.control-group').removeClass('error');
            }

        });
        $(function () {
            // makes form field highlighting work with bootstrap css on post backs
            $('.input-validation-error').each(function (i, element) {
                $(element).closest('.control-group').not('.error').addClass('error');
            });
        });
+5
source share
4 answers

You specify the identifier "#form" in your selector. Try removing # from your selector.

eg,

$('form input[type=submit]').click(function () {
      alert('ss');
      tinyMCE.triggerSave();
});

Also, if I read the code correctly, tinyMCE is a dynamic element. You can associate the click event with the on function.

eg,

$("body").on("click","#yourFormID", function(e){
    your click stuff here
}
+3
source

, , , . jQuery Tiny MCE ( , ). .

, tiny_mce.js? . -, Tiny MCE.

0

TextArea tinyMce, , . :

$.validator.setDefaults({
ignore: ''

});

0

All Articles