11
October

0 Comments | 0 Shares | Urdhva Tech

Greetings from Urdhva Tech!

Thank you to people submitting "how to topics".

Q: How to make a field mandatory only if creating a record?

Lets do this,

For example lets make "Office phone" required in Accounts module.

Step 1: Create / Edit (if exists at modules/Accounts/views/view.edit.php, copy over) custom/modules/Accounts/views/view.edit.php

And have following code in function display.

function display() {
        global $mod_strings;
        $jsscript = <<<EOQ
        <script>
                addToValidate('EditView','phone_office','varchar',true,'{$mod_strings['LBL_PHONE_OFFICE']}');    // mark office phone field required
                $('#phone_office_label').html('{$mod_strings['LBL_PHONE_OFFICE']} <font color="red">*</font>'); // with red * sign next to label
        </script>
EOQ;
        parent::display();
        
if(empty($this->bean->fetched_row['id'])) // This makes sure, current action is not "edit"
            echo $jsscript; //echo the script
    }

 Voila! Done!.

[Loved how screen looks than what you have? Buy the look!]

Highlight:

if(empty($this->bean->fetched_row['id'])) is the key! Do something ONLY for new records!

Hope that helps! Post comment below.

Keep posting how-to topics! Excited to start off with first how to on request!

Related: Required conditionally if dropdown X has value Y.

 

 

Download attachments:
Comments
  • No Comments Found.
Post your comment