⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Default Field value that changes depending on another Field



ChrisCross
  • profile picture
  • Member

Posted 27 November 2019 - 06:33 AM

Simply put, I need to automatically "create" a code that includes a field's value as part of a string.

This is what I currently have;

public function addsite()
{
        $crud = $this->_getGroceryCrudEnterprise();

        $crud->setTable('Companies');
        $crud->setSubject('Sites', 'Site');

        $crud->columns(array('Name','ContactName','ContactLastName','ContactNumber','ContactEmail','DateAdded'));

        $crud->displayas('ContactName','Contact Name')
             ->displayas('ContactLastName','Contact Last Name')
             ->displayas('ContactNumber','Contact Number')
             ->displayas('ContactEmail','Contact Email')
             ->displayas('DateAdded','Date Added');

        $crud->callbackaddfield('ConnectionString',array($this,'ConString_callback'));
        $crud->readOnlyFields(array('ConnectionString'));

        $output = $crud->render();
        $this->_report_output($output, 'Add a Site');  
}

function ConString_callback()
{
    return 'Data Source=myserver;Initial Catalog=foodb;MultipleActiveResultSets=True;User Id=foobar;Password=123;';

}

What this does is automatically changes the ConnectionString field to the value generated in the ConString_callback function. Now my problem is; I need the "foodb" replaced with whatever the Name field's value is without any spaces and such. This can happen on keyup or on change, or whatever works best.

How do I proceed here?