GemsTracker

GEneric Medical Survey Tracker

User Tools

Site Tools


Sidebar

Quick Links

Main site / download

API Docs
Bug tracker
Demo site
GitHub

Index

devzone:giftbox:changing_a_form_element

Changing a form element

We will change the studynumber field from editable to non-editable, so you need to change a respondent details textbox.
First create your own respondent controller if you have not yet done so (see howto).
There is only one function you need to overrule: the addFormElements function.
First the parent class is used to create your form, then it gets the tab on which your element sits, and adds the same element again as Exhibitor element:

    /**
     * Adds elements from the model to the bridge that creates the form.
     *
     * Overrule this function to add different elements to the browse table, without
     * having to recode the core table building code.
     *
     * @param MUtil_Model_FormBridge $bridge
     * @param MUtil_Model_ModelAbstract $model
     * @param array $data The data that will later be loaded into the form
     * @param optional boolean $new Form should be for a new element
     * @return void|array When an array of new values is return, these are used to update the $data array in the calling function
     */
    protected function addFormElements(MUtil_Model_FormBridge $bridge, MUtil_Model_ModelAbstract $model, array $data, $new = false)
    {
        parent::addFormElements($bridge, $model, $data, $new);
 
        // show studynr non-editable and add a validator at the same time
 
        $bridge->getTab('caption1');
        // The simple version:        
        $bridge->addExhibitor('gr2o_patient_nr');
 
        // The advanced option: add a validator as well
        /*
         * $bridge->addExhibitor('gr2o_patient_nr')
               ->addValidator(  $model->createUniqueValidator(array('gr2o_patient_nr', 'gr2o_id_organization'), array('gr2o_id_user' => 'grs_id_user', 'gr2o_id_organization')));
        */
 
    }

This will replace the original element with the new layout.
In the advanced option, we added a validator that will check if the combination of patientnr and organizationid is unique (first array), excluding the current edited record (second array).
This might look confusing, but that's why it is an advanced option!

devzone/giftbox/changing_a_form_element.txt · Last modified: 2020/03/12 12:06 (external edit)