Daniel7157685
Posts: 0
Joined: Thu Oct 09, 2014 7:31 pm

Javascript to select radio button on database query not working after upgrade

I had this working, but with the new upgrade it's broken. I'm hoping someone can give me a hand and let me know what happened and if there is some other way I should do this now.

Essentially what I'm doing is reading info from a database, in this instance it's the category field. This field was entered into the database in by a different create form with the options as radio buttons and then stored in the database as text for later recall. When someone is viewing an entry and wants to edit it they pull up the edit form. This form is the exact same as the entry form except that it's pre populated with data from whatever entry they are editing. So the name, the address, etc are all easy to fill in, but I want the radio buttons for several options filled in with what is already in the database. I was using the following code to accomplish this, but it has now stopped working.

code
if (value == "Restaurants"){
Appery("mobileradiobutton_40").find("input[type=radio]").prop("checked", true); //select radiobutton
$('input[name=mobileradiogroup_31]').each(function(){$(this).checkboxradio("refresh")}); // refresh all radio buttons in group
}

if (value == "Banks & ATMs"){
Appery("mobileradiobutton_32").find("input[type=radio]").prop("checked", true);
$('input[name=mobileradiogroup_31]').each(function(){$(this).checkboxradio("refresh")});
}

if (value == "Bars & Entertainment"){
Appery("mobileradiobutton_33").find("input[type=radio]").prop("checked", true);
$('input[name=mobileradiogroup_31]').each(function(){$(this).checkboxradio("refresh")});
}

if (value == "Government"){
Appery("mobileradiobutton_34").find("input[type=radio]").prop("checked", true);
$('input[name=mobileradiogroup_31]').each(function(){$(this).checkboxradio("refresh")});
}
/code

There are more categories, but I was checking them all the same way so I cut it off for brevity.
Thanks.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Javascript to select radio button on database query not working after upgrade

Hi Daniel,

Could you please clarify what doesn't work? Please try debugging:
http://devcenter.appery.io/documentat...

What is the value of variable 'value'?

Daniel7157685
Posts: 0
Joined: Thu Oct 09, 2014 7:31 pm

Javascript to select radio button on database query not working after upgrade

Maybe this picture will help explain better. When I try to map "Type" from my response it is returning the value of one of the radio buttons in mobileradiogroup_31, I want whatever the value it is returning to be the button that is selected on the form. So 'value' is the data coming over from the query. If the database record has "Restaurants" for the type then I want "Restaurants" to be the highlighted radio button when someone pulls up the edit form. It's essentially just pulling information from a record in the database, pre populating an entry form with it, letting the user change it, and then resubmit it into the database. You can see where I have this javascript located on the picture. It was working fine before, but now when I go to edit an entry the radio button group shows up with none of them selected. The text input fields still work fine.

Image

Daniel7157685
Posts: 0
Joined: Thu Oct 09, 2014 7:31 pm

Javascript to select radio button on database query not working after upgrade

Two more pics that may help, first an example entry.
Image
Next when I hit the edit button, the form is filled out with this entry. Bar & Entertainment should be the selected radio button because that is how this entry is listed in the database. None of the radio buttons are selected though.
Image

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Javascript to select radio button on database query not working after upgrade

Hi Daniel,

Please try following code:

pre

console.log("type value is = '" + value + "'");

if (value == "Restaurants")
Appery("mobileradiobutton_40").find("input[type=radio]").prop("checked", true).trigger("click"); //select radiobutton

if (value == "Banks & ATMs")
Appery("mobileradiobutton_32").find("input[type=radio]").prop("checked", true).trigger("click"); //select radiobutton

if (value == "Bars & Entertainment")
Appery("mobileradiobutton_33").find("input[type=radio]").prop("checked", true).trigger("click"); //select radiobutton

if (value == "Government")
Appery("mobileradiobutton_34").find("input[type=radio]").prop("checked", true).trigger("click"); //select radiobutton

/pre

This code has some log to be sure you have correct value and should help to debug. Please open browser console and check it.

Regards.

Daniel7157685
Posts: 0
Joined: Thu Oct 09, 2014 7:31 pm

Javascript to select radio button on database query not working after upgrade

Hi Yurii,
I tried your code, but it still doesn't seem to be working. The only error I'm getting in the console is this one:
Image

You can also see here where the query is returning "Bars & Entertainment" under the Type field, but it is not ticking that radio button above.
Image

Thanks for your help.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Javascript to select radio button on database query not working after upgrade

Hi Daniel,

Please give us your app public link and describe steps to reproduce your problem.

Thanks & regards.

Daniel7157685
Posts: 0
Joined: Thu Oct 09, 2014 7:31 pm

Javascript to select radio button on database query not working after upgrade

Hi Yurii,
Here is the puiblic link http://appery.io/app/mobile-frame?src...

  1. Select restaurants

  2. Select any of the entries

  3. Scroll down to the bottom of the details screen and select edit entry

  4. You will see the radio buttons don't select themselves with the current data on this edit screen as I have been describing above. The restaurant radio button under categories should be selected because this entry is from the restaurant category. It used to work under the old version with the old code I posted at the start of this thread.

    I hid the submit button on the edit form because I don't want anyone messing with the data right now, but you should still see the problem I'm having.
    Thanks again.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Javascript to select radio button on database query not working after upgrade

Hi Daniel,

Thanks for your details description.

I've been able to reproduce it. And find a problem that stops JS code..

See details:

http://prntscr.com/4vzjox/direct

So please fix this problem and we will continue.

Regards.

Daniel7157685
Posts: 0
Joined: Thu Oct 09, 2014 7:31 pm

Javascript to select radio button on database query not working after upgrade

I'm not sure how I am supposed to go about fixing this, it's not from any of the code I wrote. The problem it keeps showing me is this line in the component-manager.js. Do you think I should submit something through the support email?
Thanks Yurii.
Image

Return to “Issues”