Formatting

QuestionsFormatting
Matt asked 1 year ago

Two questions: Is there a way to force input on the grid edit form to all uppercase?
If I want the default value of a column to be the value of another column in the same table can that be done and how?

7 Answers
Abu Ghufran Staff answered 1 year ago

For 1)
If you want to do on client side:

You can set them using editoptions
 
$col = array();
$col[“title”] = “Name”; // caption of column

$col[“editoptions”] = array(“onkeyup”=>”this.value=this.value.toUpperCase()”);
$cols[] = $col;

To do this on server side, you can connect on_insert OR on_update event handler and make it strtoupper(). e.g.

$e[“on_insert”] = array(“add_client”, null, true);
$grid->set_events($e);
 
function add_client($data)
{
  $data[“params”][“fullname”] = strtoupper($data[“params”][“fullname”]);
}
 
// where fullname is $col[“name”] you want to store in caps.

_________________________
Abu Ghufran - Dev Team
PHP Grid Framework
 
Abu Ghufran Staff answered 1 year ago

For 2) Please tell when you need to set default value. Is it on add or edit? if edit, dialog or inline?
Is the field exist in grid from which value need to be read?

_________________________
Abu Ghufran - Dev Team
PHP Grid Framework
 
Matt answered 1 year ago

Thanks I’ll try that for my all caps issue.

For the second part I would like to have a default edit value. For example: User_Level would be displayed with the current level of Guest, Registered User, or Admin in the original column and then a second column of New_User_Level would be defaulted to whatever the current user level is set to so the admin could leave it as is or better change it.

Matt answered 1 year ago

Also, this would be for the inline edit.

Abu Ghufran Staff answered 1 year ago

For #2, Demo here: line 51

It loads value of field ‘name’ in ‘gender’ on form load and inline edit.

https://gist.github.com/gridphp/083c3162d0ddead1942c812a20fe6031#file-other-field-default-value-php-L51

_________________________
Abu Ghufran - Dev Team
PHP Grid Framework
 
David answered 1 month ago

I feel stupid but I tried the above and my page errors out.  What am I doing wrong to the underlined portion?

$col = array();
$col[“title”] = “DBA”;
$col[“name”] = “dba”;
$col[“align”] = “center”;
$col[“width”] = “40”;
$col[“editable”] = true; // this column is editable
$col[“editoptions”] = array(“size”=>25); // with default display of textbox with size 20
$col[“editoptions”] = array(“onkeyup”=>”dba=dba.toUpperCase()”);
$col[“editrules”] = array(“required”=>true); // and is required
$cols[] = $col;

Abu Ghufran Staff answered 1 month ago

Hello,

dba = dba.toUpperCase() may not work, instead of this.value = this.value.toUpperCase()
Also editoptions array is getting overrided and size=>25 will be ignored.

Try this:

$col = array();
$col["title"] = "DBA";
$col["name"] = "dba";
$col["align"] = "center";
$col["width"] = "40";
$col["editable"] = true; // this column is editable 
$col["editoptions"] = array("size"=>25, "onkeyup"=>"this.value=this.value.toUpperCase()");
$col["editrules"] = array("required"=>true); // and is required 
$cols[] = $col;

 

_________________________
Abu Ghufran - Dev Team
PHP Grid Framework
 
Your Answer

0 + 10 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating / 5. Vote count:

We are sorry that this post was not useful for you!

Let us improve this post!