Google Appmaker: Update form based on selected dropdown option - google-app-maker

I have an AppMaker app that has a from based off of one address table/datasource. I can get a form with next/prev buttons, but replaced the key field (name) with a dropdown list of all names (a user can start typing names to jump there, with the dropdown showing).
My hope is that when a user selects from the dropdown, the entire form updates and the next/prev buttons work properly as well (there too many records to page thru with next/prev only). I don't have to have next/prev functionality if it complicates things too much.
Currently the dropdown is working, but I cannot get the index for the next/prev buttons set or the rest of the form to reflect the selected dropdown record.
I've tried to set the "onValueEdit" event to something like this...
var selected = widget.value;
var idx = widget.options.indexOf(selected);
console.log("Selected: "+selected+", index = "+idx+"\n");
if(idx < 0) { //...this error is never hit
console.log("Index error - setting to zero!\n");
idx = 0;
}
widget.datasource.loadPage(idx); //...update form?
Two observations via console logging:
The "idx" var is never set to the selected dropdown index reliably, and is
often "0" (tho no error msg ever shows), so the "indexOf()" function
isn't working as expected.
The "selected" var (name) is always correct.
If I call widget.datasource.loadPage(...) with a fixed value (say 5) it has no effect on what is shows in the form either (previous loaded data remains) - obviously not the way to do it :v/
Can you steer a noob in the right direction?

If you are using default App Maker form, then you can see that so-called pager, doesn't actually paginate. It triggers prevItem/nextItem datasource methods, in other words it navigates through datasource items, not pages. Here is a quote from App Maker docs:
nextItem: Selects the next item. For Query Datasources, if the current item is the last item on the page, then this loads the next page and selects the first item on the newly loaded page.
So, if you already have all your items loaded(you set query page size for your datasource to 0), then you need just to change selected item within datasource:
// onValueEdit dropdown event
// assuming, that form and dropdown share same datasource
widget.datasource.selectKey(newValue._key);
If you really have lots of items and it is not feasible to load all of them in one call... then it will be all another story...

UPDATE:
It's important that Options and Value are set as shown in the image below!
However, I had trouble setting them that way (read: wasted hours!) until I wiped them both completely using More options in the binding picklist, and tried again (I had even tried on a brand new app!). I was being forced to choose ..projections.. and then a final field before the OK button would be available.
Not sure if AppMaker is buggy here or there is something simple I'm not understanding!
None of the coding in my original question is required.
Once set this way, binding just works as you would expect it!!
All other fields are set as #datasource.item. and are bound to whatever item is chosen. No Events settings are necessary for the dropdown either, as I thought they might be.

I deleted this page and started again, and replaced the default business name data field with a drop down, I set the dropdown as:
Options: #datasources.Addresses.items
Value: #datasources.Addresses.item
It works fine?! Not sure what happend in my original page!
UPDATE:
So it seems you need to delete both the Value and Options and then re-enter these. The OK will light up when you do.
Also, my original take on App Maker was to build the UI and attach data. That was my first mistake. You build the data then have App Maker build edit/add pages for you.

Related

Can't access SelectedNode Value from asp Treeview in javascript

I have an asp page that has a Treeview on it that is populated in code behind (so not data-bound). As I expand the nodes eventually the list of item becomes so big that after the postback, I lose where I was in the tree. So I've been looking into using client-side script to use scrollIntoView but all the examples of how to get the current selected node (the node I just expanded), seem to fail for me.
var elem = document.getElementById('navTree_SelectedNode');
alert(elem.value);
For me the .value is always null, as though no item has been selected. I've tried calling this code on the window.load and also by running a script from the code-behind. So I know there are lots of posts of this is how to do it, but I can't get an ID back of the item so I can then do a document.getElementById() on to then run the scrollIntoView. Maybe I'm trying to access the value too early/late and it's not been set, so where would the best place for me to check this be?
I've also tried accessing it with:
var test = document.getElementById('navTree_Data.selectedNodeID');
and still no luck.
Just a thought, selected is the item I have just clicked on to expand, not Checked as the nodes have check boxes?
Many thanks
The issue was being caused by the .SelectAction on my nodes being set to TreeNodeSelectAction.Expand when it should be set to .SelectExpand.

Use multiple App Maker fragment forms on the same page

So if I have a customer lookup fragment form (i.e. name to lookup and displays address), then need a page with a from and to customer, is there a way to isolate the data binding so that both can be individual?
Currently I can only get the same data to show up in either and so changing one effects the other.
You can override page fragment's datasource:
Once you check 'Override page fragment datasource' checkbox, datasource property will become editable.
Ah got it! In part to what #Pavel responded with....
So in the fragment, the data source is set up pretty much normally:
In the inserted fragments, settings are as follows:
- over-ride checked
- datasource: #Datasources.Addresses.items
Both fragments now act individually on selected name.

ASP.Net Code Optimization

I have almost every piece of code, I just need it to be optimized using correct IF_ELSE conditions and arranging the right flow.
I have a webform (UserProfile.aspx), which contains FormView (to display user profile).
In FormView ItemTemplate, I have put simple HTML and ASP.Net Labels to display Info using Label's Text property :
Eval("col_name");
In EditItemTemplate, I have same table with but textboxes instead of Labels.
I have a button "Edit", on its Click event, I'm changing FormViewMode
FormView1.changeMode(FormViewMode.Edit); [ WORKING ]
I have another button "Cancel", on its Click event, I'm changing FormViewMode
FormView1.changeMode(FormViewMode.ReadOnly); [ <-- NOT WORKING ]
To display user profile, I'm passing user-id from querystring (querystring field = "user")
So the valid URL looks like :
/UserProfile.aspx?user=121
What I want to achieve is :
If (user_IS_Logged_In)
//Some basic tasks like setting welcome message label with username/email etc.
If (querystring_is_EMPTY OR querystring_field_is_incorrect OR user_IS_NOT_Logged_IN)
//Remove the Edit and Cancel buttons
If (querystring_field_is_exist)
//initialize user_id (this will be passed to ShowUserDetails(user_id))
If (user_IS_Logged_In AND querystring_is_exist)
If querystring value and logged in user_id ARE NOT EQUAL THEN
//Again Remove the Edit and Cancel buttons
P.S --> I'm thinking to add an UpdatePanel around the FormView Once I achieve above tasks, for consistent look.
I know the problem is quite difficult to understand so feel free to ask details.
I will provide the code as needed.

ASP.Net MVC make Html.DropDownList unselectable

I would like display some Html.DropDownList controls in custom readonly mode.
Control should be able to open underlaying popup but it shouldn't save values that selected by user.
For example I have Html.DropDownList control with three values:
Value 1
Value 2
Value 3
Selected item for control "Value 2"
User see combobox control with displayed item "Value 2".
When user click on control popup with all three values should be opened (as for usual combobox control). In case user choose value different from "Value 2" selected value shouldn't be saved in control. So, when user click on item "Value 3" from underlying list, control should still display item "Value 2" as selected
Is it possible in any way?
Thank you
Ugh. As a user of your system, I will not like what you have created here! The first time I try to click on Value 3, and it pops back to Value 2 without any warning, I will assume that I mis-clicked, and I will immediately try again. Hopefully I will realize that you are re-setting that dropdown list, but I won't get it right away, and I'll be annoyed.
Here's a better UI choice: Disable the invalid OPTION tags so that I can see them in the dropdown, but I can't select them. Here's the jQuery for it:
$(function () {
$("#select[name=test] option").not(":selected").attr("disabled", true);
});
I learned from an experienced programmer (not even a 'real' design guy), that the biggest sin of UI design is allowing the user to select an invalid option. Do everything in your power to avoid have to 'correct' what the user picked. By allowing them to select an invalid option, and then un-doing it instantly with JavaScript without any user feedback, you are violating this guideline.
If you are ok. with using jQuery. This should work for you.
(function () {
var previous;
// Grab the initial value in focus event.
$("select[name=test]").focus(function () {
previous = this.value;
// On change event, use previous to set the value of dropdown.
}).change(function() {
$("select[name=test]").val(previous);
});
})();​
Here is the working example.
Inspired by another StackOverflow answer.

CheckedListBox Item Selection

I have created a site that allows users to see a list of files that currently reside on my FTP site.
I have got the files appearing but when I select one and click download, it is not registering that I have selected an item.
At the moment I am using:
If CheckBoxList1.SelectedItem.Value = "" Then
MsgBox("A file needs to be selected...!")
End If
'NOTE - A SELECTION ISN'T BEING RECORDED BY THE PROGRAM!!'
If CheckBoxList1.SelectedItem.Value <> "" Then
I think that it is not registering the selection being made, because the item being selected is not a string value.
But I am not sure what to set this as.
It would help if you provided the actual code being used to attach the selection / change handler as well as the event method body.
I'm guessing your attaching to the checkbox SelectedIndexChanged event. If that's the case then make sure that you have actually bound a "value" to the checkbox list, ensure that you are using the "DataTextField"and "DataValueField" properties instead of just default binding the checkboxlist to a collection.

Resources