2

私のモジュールrules_name_cには、テキスト フィールドとrules_author_cリレート フィールドの 2 つのフィールドがあります。

これらのフィールドは必須フィールドではありませんが、フィールドにデータを入力するときに、レコードを完成させるために入力rules_name_cする必要があるようにしたいと考えています。rules_author_c

私は次のことを試しました:

<?php

require_once('include/MVC/View/views/view.edit.php');
/*
 * replace UT_Blogs with the module your are dealing with 
 */

class conn_connectionViewEdit extends ViewEdit {

    public function __construct() {
        parent::ViewEdit();
        $this->useForSubpanel = true; // this variable specifies that these changes should work for subpanel
        $this->useModuleQuickCreateTemplate = true; // quick create template too
    }

    function display() {

        global $mod_strings;
        //JS to make field mendatory 
        $jsscript = <<<EOQ
                   <script>
                       // Change rules_author_c to the field of your module
                       $('#rules_name_c').change(function() {
                            makerequired(); // onchange call function to mark the field required
                       });
                     function makerequired()
                     {
                        var status = $('#rules_name_c').val(); // get current value of the field 
                         if(status != ''){ // check if it matches the condition: if true,
                                addToValidate('EditView','rules_author_c','varchar',true,'{$mod_strings['LBL_RULES_AUTHOR']}');    // mark rules_author_c field required
                                $('#description_label').html('{$mod_strings['LBL_RULES_AUTHOR']}: <font color="red">*</font>'); // with red * sign next to label
                            }
                            else{
                                removeFromValidate('EditView','rules_author_c');                        // else remove the validtion applied
                                $('#rules_author_c_label').html('{$mod_strings['LBL_RULES_AUTHOR']}: '); // and give the normal label back 
                            }
                    }
                    makerequired(); //Call at onload while editing a Published blog record
                </script>
EOQ;
        parent::display();
        echo $jsscript;     //echo the script
    }

}
4

1 に答える 1