Formatting

QuestionsFormatting
Matt asked 5 years 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 5 years 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
Grid 4 PHP Framework
 
Abu Ghufran Staff answered 5 years 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
Grid 4 PHP Framework
 
Matt answered 5 years 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 5 years ago

Also, this would be for the inline edit.

Abu Ghufran Staff answered 5 years 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
Grid 4 PHP Framework
 
David answered 4 years 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 4 years 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
Grid 4 PHP Framework
 
Your Answer

13 + 7 =

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 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

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

Let us improve this post!

Tell us how we can improve this post?