Set default value for a column on edit dialog only

QuestionsSet default value for a column on edit dialog only
E Mello asked 8 years ago

Hi,

I've got a date type column and would like to display today's date as default value when opening the edit dialog.
Displaying the column value in the grid*, it should be empty.
If I use col["default"], the grid shows today's date for that column, and don't want that. It has to be displayed only as a suggested value on the edit dialog only.
Any help? Thanks.
* Full version.

7 Answers
Abu Ghufran answered 8 years ago

You can use:

$col["editoptions"]["value"] = date("Y-m-d"); // or any other date format.

When you click on calendar icon next to date field, it shows current date focused.

E Mello answered 8 years ago

Thanks for your reply Abu.
You said "When you click on calendar icon" – it works, but that's not what I want.
I would like to set the date when you open the edit dialog (the date is already displayed on the edit dialog) – which means the user does not need to click on the calendar icon if he wants todays date (as it is already filled in).
Is there any work around for this?
Thanks.

Abu Ghufran answered 8 years ago

When you edit a record, the previous value saved in database is auto filled in field.
Do you want to ignore the old db value and prefill with current date?

$opt["edit_options"]["afterShowForm"] = 'function () { $("#invdate").val("'.date("Y-m-d").'"); }';
$g->set_options($opt);

// where invdate is field name.

If you want to set it while adding record,
$col["editoptions"]["defaultValue"] = date("Y-m-d");

The defaultValue date format and the formatoptions["newformat"] date format must be same to fill field.

E Mello answered 8 years ago

Yes, that's exactly what I want.
We are almost there.
It works if the edit mode is a dialog via double click.
If it is in inline edit mode, it does not show the date pre filled.

if other words, if I add this script below, works.
if I remove this script, it doesn't.

<script>
var opts = {
'ondblClickRow': function (id) {
jQuery(this).jqGrid('editGridRow', id, <?php echo json_encode_jsfunc($g->options["edit_options"])?>);
}
};
</script>

Thanks for assisting me again.

E Mello answered 8 years ago

Typo above
* In other words

Abu Ghufran answered 8 years ago

Currently it is not doable in inline edit mode.
It will require some core lib changes.

E Mello answered 8 years ago

Hum ok then.
Thanks anyway.

Your Answer

6 + 18 =

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?