⚠ 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 values (select and text)



titu
  • profile picture
  • Member

Posted 13 May 2015 - 21:32 PM

Maybe this solution already exists but needed a fast way to implement, so the only thing to add is on the template (on the example offices.php) add at the end:

 

<?php

echo <<<EOT
<script>$(document).ready(function() {
EOT;
if(isset($selectDefault)){

foreach ($selectDefault as $key => $value) {
echo <<<EOT
document.getElementById("$key").value = '$value';
$("#$key").trigger("liszt:updated");
EOT;
}
}
if(isset($textDefault)){
foreach ($textDefault as $key => $value) {
echo <<<EOT
document.getElementById("$key").value = '$value';
EOT;
}

}

echo "});";
echo "</script>";

?>

 

And on the controller 

just add:

 

$output = $crud->render();
//For input text:
$output->textDefault=array("field-name"=>$value);
//For input select:
$output->selectDefault=array("field-state"=>'COMPLETE');
$this->_example_output($output);

 

the array key is the id of the field that is "field-"+ field name.

 

Hope it is clear enough.

 

 

 

 


Adriano Gonçalves
  • profile picture
  • Member

Posted 09 October 2015 - 10:28 AM

It sounds a good and simple approach.

 

Thanks!