Drop Down Default Value Unless Changed

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
Kire5
Posts: 7
Joined: 2014-07-27 13:07

Drop Down Default Value Unless Changed

Post by Kire5 » 2015-10-10 11:31

Hi everyone,

I have a debacle and am hoping someone could lend a hand... really bright crowd we have here =)

I have a list of Characters, each of which are an Animal. I have an Animals table and a Characters table. The setup is that the user adds animals to the animals table (Lion, Hippo, etc) and adds characters to the character table and uses a dropdown lookup there to specify what sort of animal that character is.

Now, for the upcoming party, each character has the option of dressing as a different animal than they really are, or coming dressed "as-is'.

So we have another table with a form (pictured). If I select "Robbie", the read-only Animal lookup pulls which animal Robbie is from the character table. I then have a dropdown right below that where I can state what, if anything, Robbie is coming dressed as to the party.

My question is... can I somehow make that dropdown automatically change to whatever the value of "Animal" is UNLESS manually changed by the user? What I'd love to see happen is the value of "Dressed As" change to match "Animal" each time the user selects a new character in the Character dropdown, but still have the ability to edit that value. 9/10 Characters are coming dressed as themselves, so I'd like the user to not have to changed "Dressed As" unless that character is one of the exceptional cases.
robbie.png
robbie.png (5.38 KiB) Viewed 4010 times
In this pic, I'd like to see "Dressed As" change to "Rabbit" when the user selects "Robbie"... but give the user the ability to still changed "Dressed As" to any other value available in that dropdown. "Animal" can remain locked down, but 'Dressed As' needs to be editable.

Any help, or alternate solutions would be very welcome... many thanks!

ahmed hamdy
Posts: 3
Joined: 2015-10-31 18:33

Re: Drop Down Default Value Unless Changed

Post by ahmed hamdy » 2015-11-05 20:02

ok

after you get the id of drop down list you can add this code

Code: Select all

<script>
$j(function(){
$j(#id).select2({
ajax:
{
url:'ajax_combo.php',
datatype:'json',
cache:true,
data:function(term,page){return {s:term,p:page,t:table,f:field};},
result:function(resp,page){return resp;}
}
}).on('change',function(e){$j(#id).val(e.data.text)});
});

if($j().val.length)
{
$j.ajax({
url:'ajax_combo.php',
datatype:'json',
cache:true,
data:{s:$j(#id).val(),p:page,:table,f:field}
}).done(function(resp){
if(resp.result.length)
{
$j(#id).select2('data',
{
id:resp.result[1].id,
text:resp.result[2].text
});
}
});
}
})
</script>

thecomputerchap
Veteran Member
Posts: 47
Joined: 2016-08-28 10:37

Re: Drop Down Default Value Unless Changed

Post by thecomputerchap » 2017-02-28 11:10

Hi Ahmed,

I'm trying to change the value of a lookup field after an Ajax call on a different field. I'm using...

$j('#pulldown-container').val(1).trigger("change");

in accordance with the select2 documentation at https://select2.github.io/examples.html but when I test it the console is saying...

722 TypeError: undefined is not an object (evaluating 'e.added.id')

Any ideas how I can achieve this?

Thank you :)

Post Reply