afterInsertRow seting default value

QuestionsafterInsertRow seting default value
Gerhard asked 6 years ago

Hi Abu,

I want to click add on the grid in inline mode.
New add row is added and I found the function afterInsertRow where I can do something.

But I dont have any idea how I can set default values on it depending on other columns.

for Example (after click on add):
3 Columns (1st Dropdown, 2nd Date, 3rd Text)
So if I press add I want to set default value on 3rd Column depending on selected entry on 1st Dropdown value)

So when I choose value 1 of Dropdown (1st column) I want to change value of the textbox (3rd column).

Is there any possibility to do so?

thx a lot, Gerhard

4 Answers
Abu Ghufran answered 6 years ago

On first dropdown you can connect JS function on change event.
$col["editoptions"]["onchange"] = "update_field();"

and in html code:

<script>
function update_amount()
{
var v = parseFloat(jQuery("select[name=dd1].FormElement, select[name=dd1].editable").val());
// custom logic to change dd2
jQuery("select[name=dd2].FormElement, select[name=dd2].editable").val( v );
}
</script>

where dd1 is dropdown to pick value and dd2 is which need to be changed.

More info:
http://www.phpgrid.org/faqs/#80
https://gist.github.com/gridphp/db81eae4b5b9ce26bd59287ab13ad42c

Gerhard Stark answered 6 years ago

thx Abu,

helped me a lot.

Is it also possible to set min and max for the second field depending on first field?

Example:
Dropdown Value = 2
Textfield depends on Dropdownvalue 2 == min 0.2 max 1.4

or do I have to write this in js then?

thx a lot.

Gerhard

Abu Ghufran answered 6 years ago

You need to write JS code in onchange callback

Gerhard Stark answered 6 years ago

Many thx for your help!

regards, Gerhard

Your Answer

7 + 5 =

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?