textarea为空时禁用表单提交按钮

时间:2018-01-25 11:44:49

标签: javascript php jquery forms

这是一个wp前端帖子提交表单。标题和内容区域需要填写,如果没有提交按钮则不可点击。所需的标题对我来说还可以,但我需要将内容区域设为可选。我相信它是由JavaScript完成的 我找不到如何将文本区域更改为可选或我发现的不起作用。我应该在这里改变什么

JavaScript的:

     * set validate form condition
    */
    this.submit_validator   = $("form#submit_question").validate({
        rules   : {
            post_title          : "required",
            question_category   : "required",
            post_content        : "required",
        },
        messages: {
            post_title          : qa_front.form_auth.error_msg,
            question_category   : qa_front.form_auth.error_msg,
            post_content        : qa_front.form_auth.error_msg,
        }
    });

    if(ae_globals.user_confirm && currentUser.register_status == "unconfirm"){
        AE.pubsub.trigger('ae:notification', {
            msg: qa_front.texts.confirm_account,
            notice_type: 'error',
        });
        return false;
    }

    if(currentUser.ID == 0){
        AE.pubsub.trigger('ae:notification', {
            msg: qa_front.texts.require_login,
            notice_type: 'error',
        });

另一个JavaScript

// initialize modal question

            initialize: function() {
                this.blockUi = new AE.Views.BlockUi();

            },
            submitReport: function(event){
                event.preventDefault();

                var view    = this,
                    form    = $(event.currentTarget),
                    message = form.find('textarea#txt_report').val(),
                    data    = form.serializeObject(),
                    $button = form.find("input.btn");

                this.model.set('do_action', 'report');
                this.model.save('data',data, {
                    beforeSend: function() {
                        if( message == '' ){
                            AE.pubsub.trigger('ae:notification', {
                                msg: qa_front.form_auth.error_msg,
                                notice_type: 'error',
                            });
                            return false;
                        }
                        view.blockUi.block($button);
                    },
                    success: function(result, status, jqXHR) {
                        view.blockUi.unblock();
                        if(status.success)  {
                            view.closeModal();
                            AE.pubsub.trigger('ae:afterReport', {
                                msg: status.msg,
                                notice_type: 'success'
                            });
                            view.stopListening(AE.pubsub, 'ae:afterReport');
                        }
                        else{
                            AE.pubsub.trigger('ae:notification', {
                                msg: status.msg,
                                notice_type: 'error',
                            });
                        }
                        $("form#report_form")[0].reset();
                    },
                });
            },
            setModel : function (model) {
                this.model = model;
            },
        });
    }

还有一个JavaScript:

cbUploaded: function(up, file, res) {
                    if (res.success == true) {
                        var textarea = $(upload_textarea);
                        var post_content = textarea.val();
                        $('.body-poll, .body-question').each(function(){

                            if(!$(this).hasClass('hide')){
                                console.log($(this).data('name'));
                                if($(this).data('name') == 'poll'){
                                    tinymce.get('insert_poll').execCommand('mceInsertContent', false, "[img]" + res.data + "[/img]");
                                }else{
                                    tinymce.get('post_content').execCommand('mceInsertContent', false, "[img]" + res.data + "[/img]");
                                }
                            }
                        })
                        post_content = post_content + '[img]'+ res.data +'[/img]';
                        textarea.val(post_content);
                    } else {
                        AE.pubsub.trigger('ae:notification', {
                            'notice_type' : 'error',
                            'msg' : res.msg
                        })

                        view.blockUi.unblock();
                    }
                },
                beforeSend: function() {
                    view.blockUi.block($upload_image_button);
                },
                success: function() {
                    view.blockUi.unblock();
                }
            });
        },
        /*
         * Show notification
         */
        showNotice: function(params) {
            var view = this;
            // remove existing notification
            $('div.notification').remove();

            var notification = $(view.noti_templates({
                msg: params.msg,
                type: params.notice_type
            }));

FORM:

<?php
define( 'MOBILE_PATH', dirname(__FILE__) );
/**
*
* TEMPLATE FILTER QUESTIONS FOR MOBILE
* @author ThaiNT
* @since 1.0
*
**/
if( !function_exists('qa_mobile_submit_questions_form')){
function qa_mobile_submit_questions_form(){
    global $current_user;
    $role = get_user_role($current_user->ID);
    $privi  =   qa_get_privileges();
    ?>
    <section class="post-question-form-wrapper">
        <div class="container no-padding">
            <div class="tabs-title">
                <ul>
                    <li><span class="title-bar-tab active" id="tab-question"><?php _e('Ask a Question', ET_DOMAIN);?></span></li>
                    <?php if(ae_get_option('poll_maker') !=="0") { ?>
                    <li><span class="title-bar-tab" id="tab-poll"><?php _e('Create a Poll', ET_DOMAIN);?></span></li>
                    <?php } ?>
                </ul>
            </div>
            <div class="form-active-question">
                <div class="body-question" data-name="question">
                    <form id="submit_question" action="">
                        <input type="hidden" id="qa_nonce" name="qa_nonce" value="<?php echo wp_create_nonce( 'insert_question' ); ?>">
                        <input id="add_tag_text" type="hidden" value="<?php printf(__("You must have %d points to add tag. Current, you have to select existing tags.", ET_DOMAIN), $privi->create_tag  ); ?>" />
                        <div class="form-post">
                            <input type="text" name="post_title" id="question_title" placeholder="<?php _e("Your Question", ET_DOMAIN) ?>">
                            <span id="charNum"><?php echo ae_get_option('max_width_title', 150);?></span>
                        </div>
                        <div class="form-post">
                            <div class="select-categories-wrapper">
                                <div class="select-categories">

                                        <option value=""><?php _e("Select Category",ET_DOMAIN) ?></option>
                                        <?php
                                            $terms = get_terms( 'question_category', array('hide_empty' => 0, 'orderby'    => 'term_group' ) );
                                            $value_type = 'slug';
                                            foreach ($terms as $term) {
                                                if($term->parent == 0){
                                                    if($value_type == 'slug') {
                                                        echo "<option value='".$term->slug."'>";
                                                    } elseif($value_type == 'id') {
                                                        echo "<option value='".$term->term_id."'>";
                                                    }
                                                    echo $term->name;
                                                    echo "</option>";
                                                    foreach ($terms as $value) {
                                                        if($term->term_id == $value->parent){
                                                            if($value_type == 'slug') {
                                                                echo "<option value='".$value->slug."'>";
                                                            } elseif($value_type == 'id') {
                                                                echo "<option value='".$value->term_id."'>";
                                                            }
                                                                echo "--".$value->name;
                                                            echo "</option>";
                                                        }
                                                    }
                                                }
                                            }
                                        ?>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <?php if(ae_get_option('ae_upload_images')){ ?>
                        <div class="form-post container_upload">
                            <div class="upload_image" id="mobile_images_upload_container">
                                <a href="javascript:void(0)" id="mobile_images_upload_browse_button"><i class="fa fa-image"></i><?php _e("Insert Image", ET_DOMAIN); ?></a>
                                <span class="et_ajaxnonce" id="<?php echo wp_create_nonce( 'et_upload_images' ); ?>"></span>
                                <span id="mobile_images_upload_text">
                                <?php
                                global $max_file_size;
                                printf(__("Size must be less than < %sMB.", ET_DOMAIN),$max_file_size);
                                ?>
                                </span>
                            </div>
                        </div>
                        <?php } ?>
                        <div class="form-post">

                            <textarea name="post_content" id="" cols="30" rows="10" placeholder="<?php _e("Your Description", ET_DOMAIN) ?>"></textarea>
                        </div>
                        <div class="form-post">
                            <input  data-provide="typeahead" type="text" name="" id="question_tags" placeholder="<?php _e('Tag(max 5 tags)',ET_DOMAIN) ?>" />
                        </div>
                        <ul class="post-question-tags" id="tag_list"></ul>
                        <?php if(ae_get_option('gg_question_captcha') && $role != 'administrator'){ ?>
                            <div class="clearfix"></div>
                            <div class="container_captcha">
                                <div class="gg-captcha form-group">
                                <?php ae_gg_recaptcha(); ?>
                                </div>
                            </div>
                        <?php } ?>
                        <div class="group-btn-post">
                            <div class="container">
                                <div class="row">
                                    <div class="col-xs-5 no-pad-left"><span class="text"><?php _e("Ask a Question", ET_DOMAIN) ?></span></div>
                                    <div class="col-xs-7 text-right">
                                        <button type="submit" class="submit-post-question"><?php _e("Submit", ET_DOMAIN) ?></button>
                                        <a href="javascript:void(0)" class="cancel-post-question"><?php _e("Cancel", ET_DOMAIN) ?></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <?php
                /**

0 个答案:

没有答案