Hidden model-bound values in view not getting passed to controller when populated manually - asp.net-mvc-4

I'm using the KendoUI AutoComplete for a number of look-ups on a custom editor template that pop-ups off a grid for new rows and edits. The Kendo AutoComplete does have a DataTextField property and does not DataValueField property like a DropDownList would. So, I found I am able to get the Value of the selected item in the AutoComplete with a little Javascript and iterrogating the "dataItem" object in the select handler. And I put that value into a "SelectedID" field declared with #Html.HiddenFor(model => model.SelectedID) on the select event.
Now, when I do a save from the view and have a break point on my controller action that captures the incoming model, all those ID values where i set the value manually are empty/null/blank. I've checked the DO and have done "console.log" to read out the values of the hidden fields before the post and the values are populated. I've changed the datatypes (strings, guids, etc) and I've changed the Html Helper type as well from a HiddenFor to a EditorFor just to make sure the values are indeed there.
So i think this is a problem when the values of an element that are part of the model are populated in a "manual" fashion. The text of the AutoCompletes comes through if I bind that to a field on the model as well. Any date fields, checkboxes and free-form text fields come through as well. It seems it is just values of model bound fields where I set the values manually that don't make it over the "wire". Any thoughts? Solutions? I know the Selected Value is accessible ... it's just a matter of properly getting it into the "HiddenFor" fields.

Related

Angular5 form array validation for dynamically created fields

I am using angular5 in that I am using form array to dynamically generating the fields. Initially I want to load form array as 0 files. If I am clicking plus button I want to add two fields. With validation.
If from array is empty i.e now fields are created I have to submit the button without this dynamic fields.
If fields are created I have to set validation without entering information in fields i won't enable submit button.
If I am setting validators.required in form array I can't able to submit without entering in first two fields
I need a solution for this one guys.
Assuming you are using template driven approach, the place where you are looping through your data to generate dynamic controls, create an index variable like *ngFor=" val in collection; let i=index" and then use that i to make each control unique by appending i with the name of the control like <input type="text" name="txtId-{{i}} #txtId="ngModel" [(ngModel)]="someId" />
Now if you try to use txtId.valid inside the loop it will be unique for every row.

dojo form submit on change of value

I have a dojo table container embedded within dojo form. I'm able to validate all dijits like textbox, combobox etc and submit the form. But what I need is, submit the form only when a value is changed i.e. if a textbox value is changed, submit the form else don't.
Add a hidden text input field which is empty while loading page. Then After you make a change in your text field check the content in the hidden text field and your respective text field if they are same then don't submit the form.
Dojo input fields maintain the original value in the private attribute of '_resetValue'. Before submitting the form, you can check whether _resetValue is different from .get('value') and submit the data..
If all the attributes are under the Table container, you can fetch the children of the table containers and verify using array.every() function..
var unmodified = array.every(container.getChildren(), function(widget){
return widget._resetValue == widget.get('value');
});

xpages required property for a combobox

There is a djContainer having multiple djtabPane(s).
A combobox is situated on the first djtabPane, having the property: required="true".
but, when I move to next djtabPane in order to complete some other fields, I get the notification that the combobox value is required.
Can I achieve this property of the combobox but only if I want to submit / save the doc.?
<xe:djTabContainer id="djContentPane1" tabPosition="top" doLayout="false">
and the djTabPane ( all are the same, only the title is different ) :
<xe:djTabPane id="djTabPane1" title="Title1">
You'll need to move the validation to your save/submit method. A validator runs whenever a partial refresh happens unless you set immediate="true" or processValidators="false". But I don't think there's a way to set that on any of the in-built tabbed containers.
The advantage of Greg's approach when moving towards an MVC pattern is that the same validation can be run whenever saving the data object, not just from a specific XPage / Custom Control. The down-side is more work coding what's effectively in-built, e.g. tying the validation message back to the relevant component, setting the component's valid property to false etc.

BIRT result set values in specific cells

My query returns location_cd(string) and item_count(int). I only need certain rows from the result however and I need them to display in specific places in my layout so I don't think the table solution is going to work. Can I determine where I place the value for a particular row of the result set?
I am using a grid to display values for a number of fields. I cannot seem to be able to get the values from the results to show. The grid is bound to the result set. I even tried binding the cells to the result set but that didn't work either.
I checked in the query editor and there is a result set shown in the Preview so I know the query works. The complete and correct result set shows if I put a table on the page.
I tried inserting a Dynamic Text or Data object in a cell and used the expression:
dataSetRow["location_cd"]=="3SD"?dataSetRow["item_count"]:""
This returns a blank and does not seem to evaluate. I tested it with :
dataSetRow["location_cd"]=="3SD"?dataSetRow["item_count"]:"BLANK"
and got 'BLANK' to appear in that cell.
dataSetRow["location_cd"] and dataSetRow["item_count"] will display the location_cd and item_count from the first row of the result set. row.outer[] did the same thing. Obviously I am just hacking at this report at this point.
A co-worker suggested that she uses a JAVA if-statement in places like this but I could not get that to work either.
Any ideas or suggestions that will get me on the right road??
Thanks
An elegant option would be to use a HashMap storing the result of the dataset.
Declare a report variable named "values", with a new hashmap as default value (see image below)
Fill values in the onFetch script of the dataset: vars["values"].put(row["location_cd"],row["item_count"]);
Insert new data elements at any place of the report with expressions such: vars["values"].get("myFavoriteLocationCD");
Though it is important to note the dataset should be triggered by the report before these data elements.
The particular row you want to display you specify in a "Text" field inside your grid. Just drag and drop a "Text" field inside your grid. If you bound the fields you want to display to your grid, the "Text" field inside the grid inherits the bindings of its parent (the grid), so you can access the bindings automatically in the "Text" field.
You could try following steps, maybe that works.
Don't use "Dynamic Text" field, instead use a regular "Text" field
Ensure the fields of your query which you use, are bound to the grid (you sayed you already did)
Open the "Text" field
Change preselected pull-down entry "Auto" into "HTML"
Change preselected pull-down entry "Formatting" into "Dynamic Text"
Wrap your code in <value-of format="HTML"> your code goes here... </value-of>
Note: You should check in the "Expression Builder" of your "Text" field if you are able to access the fields you bound to the grid. If they are not available sth. went wrong with your binding. Avoid binding query records to cells this will drive you crazy.
If you want to display a list, ensure you didn't set a constant height in the row of your grid. Set the height to 100% than the row takes its height dynamically.
What about the idea to optimize your query, that only get the results you want are displayed, than you don’t need to filter them with java script? If you don’t need the filtered results in another place this would be the cleaner solution in my opinion.

How to show button cell (check box) title in table view, using bindings

I am trying a simple application where I have a mutable array of mutable dictionaries, such as -
NSMutableDictionary *sample6 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:#"title6",#"title",[NSNumber numberWithBool:NO],#"state", nil];
In IB I created a table view with NSButtonCell (check box).
I was able to show checkboxes state (checked or unchecked), using following table column bindings:
Value - ArrayController.arrangedObjects.state
In this case it shows an array of checkboxes with title - "Check" as shown in below screen-shot:
Now my aim is to show checkboxes title using bindings, such that it
gets value from same mutable dictionary from which it is getting its
state.
I tried following binding for button cell but it did not work:
title -> ArrayController.selection.title
I also tried this binding for button cell :
title -> ArrayController.arrangedObjects.title
but it didn't work, it appeared like this after using above binding:
Can any one suggest me which controller key to use and if this is not the correct way to show titles then what is the correct way to do so?
Unfortunately you'll need to write a little code if you want to do it this way. When binding table column values to an array, the table column is handling taking the prototype data cell, setting its values, and "stamping" it in place for each row. The button cell's bindings aren't exposed "through" the table column, so a simple binding won't do it for you.
To Answer Your Question
So. Since only the value binding is exposed, the title must be set manually if you really want the checkbox's title to reflect the value (ie, you really want the checkbox to handle both the check state and displaying the title). To do this, you have to mix bindings with < NSTableDelegateProtocol > . Use the -tableView:willDisplayCell:forTableColumn:row: method to set the cell's -title property to that of the proper object in your array controller's -arrangedObjects array each time you're asked. Mixing bindings and data source / delegate methods is actually quite common for more than the most basic applications, so don't worry that you're doing something dirty. Note: you won't be able to support editing the title by doing this since it's a checkbox.
An Alternative Design
Personally, I'd avoid all that and just add a separate table column for the title. Bind the new column's value to the array controller's arrangedObjects.title and turn off the checkbox button cell's title so only the checkbox itself is displayed. That simplifies the whole thing greatly and allows editing the title.