How to change a dropdown to a text box for barcode scanning into a field - google-app-maker

I have an Appmaker form to create a record that includes a many to one relation to another table. By default, the form creates a dropdown to select the related record from a list. This works fine, but I need to barcode scan (or type) the item name rather than select it.
When I change the dropdown to a text box and bind it to the related table, it greys out and becomes unusable when I preview it. (I get a circle with a line through it when hovering over.)
When I keep both the dropdown and the textbox on the same form, I can select a record from the dropdown and it populates the textbox. After that, the textbox becomes editable and works as desired.
How can I remove the dropdown and make the text box editable?

The problem is that when you bind the textbox to a relational field it is looking for a record not just a value.
My thought is you are going to want to create a text box where you enter/scan in the value and leave it unbound. then in probably the onValueChange event write a script to query the item in the related table that you are trying to relate and set that equal to the field you are trying to edit.I don't know that this code will work haven't tested it but should get you going in the right direction:
var ds = app.datasources.Parts;
ds.query.filters.Part._equals = newValue;
ds.load(function() {
if (ds.item === null) {
alert("Part not found!");
widget.root.descendants.FieldPart.value = null;
}
else {
widget.root.descendants.FieldPart.value = ds.item;
}
});

Related

C# winforms DGV Add a button to a datagrid with variable text

I know how to add a button to a datagridview. What I am having a problem with is changing the text displayed based on whether a associated record exists in another table. I would like to change the text on the button to "View SR" or "Add SR" depending on if a service request exists for the record. if it even possible, how I would go about this ?
You just need to capture the exact cell and cast it in a Grid View Button Cell to adjust the value displayed. Following is a tried solution:
if (SomeTrueValue)
{
((DataGridViewButtonCell)dataGridView1.Rows[0].Cells[0]).Value = "Hello";
}
else
{
((DataGridViewButtonCell)dataGridView1.Rows[0].Cells[0]).Value = "World";
}

Persist checkbox in gridview while custom paging

I have a created a gridview and added a checkbox in item template. This grid has few columns along with DataKey (primary key). Due to performance gain, this grid will fetch the next set of recrods on each page change based on the page number click. So that is done.
Now when user selects a checkbox in page one and then go to page 2 and coming back to page one, then user will not see the checkbox checked as the user did earlier.
So is there a good way to persist the checkbox when user move page to page?
This checkbox be used as a flag to select the rows that can be deleted later by a button outside the grid.
Since you receive a new set each time a paging is selected, I suggest the following approach:
Create an array[] object via javascript that will add to list the datakey whenever a checkbox is selected and in turn remove it if the checkbox is deselected. Something like this:
var selectedDataKeys = [];
$('.checkboxclass').on('change', function() {
// Considering you assign the data key as id for the checkbox otherwise implement a way to retrieve the id.
var dataKey = $(this).prop('id');
// Determine if the dataKey is in the selected data keys array
var isContained = (selectedDataKeys.indexOf(dataKey) > -1 );
if($(this).is(':checked')) {
// If is contained is false - add to the array
if (!isContained)
selectedDataKeys.push(dataKey);
} else {
// If is contained is true - remove to the array
if (isContained){
selectedDataKeys = $.grep(selectedDataKeys, function(value) {
return value != dataKey;
});
}
}
});
From this point on the client user will have an active list of selected items, now its up to you to use that list to manipulate your grid display page. Either modify the display on document ready by comparing all the item on the grid display with the selectedDataKeys array or sending those keys and do the comparison server side.
Hope this helps.

Invoiced Line Items ASP.NET

I have an invoice form . As you know it has Header and Line Items . When user creates invoice there can be any numner of line items.So users can click "Add Item" to add a new item and all of them needs to be saved together when user save the item.
I think I should use Grid view inside update panel with a footer row to add a new row. And save it to a table in session.When they click save invoice I can get the table from session and save those line items.
Let me know for any better approach than this.
I would create custom forms and add button that will add another line of items.
You can use jQuery append to insert div to existing container that contains all the normal fields:
$(document).ready(function() {
//dynamicId for text box's id
var dynamicId = 0
//event handler for Add button
$('#btnAdd').click(function() {
dynamicId += 1
//append <div> elements inside existing container which has
//the all fields
$('#invoiceItemsContainer').append('<div><input type="text" id="txt' + dynamicId + 'runat="server" /></div>');
});
});
When the form submitted, you can extract all the data from the text box. You do need to come up with a way to check how many line of items are on the list, but this is easy enough for you to figure out.

Change databound Drop Down List programmatically

I have a drop down list that is populated in the page load event from a database table.
The drop down has a DataTextField set to a project name and the DataValueField set to the project id (interger).
Later I change the dropdowlist selected item with this code in the selectedindexchanged event of a gridview
GridViewRow row = GridView1.SelectedRow;
ddlProjectList.SelectedItem.Text = row.Cells[2].Text;
Does Changing the drop down list with this code cause the DataValueField property to change to the correct Project ID number also? If not is there a better way to do this?
=============================================EDIT
actually this code seems to be adding an additional item to the list so that the project i set with this code is listed twice so I don't think my code is correct
This does not change anything else than the text of the selected item in your DropDownList. Do you want to change the text and value of the project, or do you want to select the project from the DropDownList that relates to the selected row in the grid?
To change the project name and id, you'll have to change it in the data source behind the ProjectList. But if you just want to select the related project, you can use this:
var row = GridView1.SelectedRow;
if (ProjectList.Items.FindByText(row.Cells[2].Text) != null)
{
ProjectList.ClearSelection();
ProjectList.Items.FindByText(row.Cells[2].Text).Selected = true;
}
Setting SelectedItem.Text does not actually change the selected item by its text, it changes the text of the currently selected item. You need to use ddl.Items.FindItemByText (or it may be worded FindByText, I forget at the moment) to find the item, then set the ListItem.Selected property to true.
HTH.
You can do
ddlProjectList.FindByText(row.Cells[2].Text).Selected = true;
This will actually set it.

Array Objects and Datagrid with Link Button (Clear Button) in Adobe Flex

I have an an array of objects. I populate the datagrid from the array. The nmber of columns in the datagrid is fix i.e.5 and the first column always shows serial number (0,1,2,3,4).
I have a link button called 'CLEAR' in the last column of the datagrid.
1> How do I make the clear button visible only when the row is particularly clicked ?
2> When the clear button is clicked, how do I make the contents of that particular row cleared. Not deleted, only cleared to insert data again. Also, the serial number (0,1,2,3,4) should not be cleared, nor deleted. How to do this ?
To make your clear button visible something like this would work.
may have to play around with it a bit.
private function onDatagridClick(event:ListEvent):void {
if ( event.rowIndex == -1 ) {
return;
}
clearBTN[event.RowIndex].visible = true;
}
If you don't want to delete your column you need to place some data in there as the datagrid is bound by the data provider you can always add dummy data i.e. blank string, "Enter data" or a custom item renderer for when data is required.

Resources