ModelState.IsValid for invisible controls - asp.net-mvc

I am working on MVC with C#.
I have 2 radio buttons. On selecting first radio button, a textbox will be shown which allows to enter date values.
<%= Html.TextBox("ReceivedDate")%>
on selecting the second radio button, the textbox gets hidden.
For the first time, when i select first radio button and entered date and clicked Next to navigate to next page and came back to this page again and clicked second radio button and clicked Next to continue and again i came back to this page and without changing any option click continue, its not allowing to navigate and shows an error.
A value is required.
Which means the ModelState validating the hidden controls also.
Please suggest how to control it

Instead of hiding it remove the element from the DOM and reinsert it if the first item is selected again. Another way would be to change the name of the input control to something else (a key not present in your model data) when the first item is not selected.
Validating hidden input types is a good thing, i often use them to synchronize data from complex controls (like a treeview with checkboxes). An input type with a hidden css style doesn't make it not submit with the form it belongs too.

Related

Adding multiple dropdown on clicking a link

I have a link which says "add another field". On clicking the link a dropdown should appear on top with let's say 5 custom fields as list in dropdown. Once user selects a field in that dropdown and clicks hyperlink another dropdown should appear below existing dropdown and with only 4 remaining fields as one is already selected.so how to start this?
https://tutorialslink.com/Articles/How-to-add-control-dynamically-in-Aspnet-MVC-using-Javascript/64 . I have tried to use this link which adds text boxes to get started.
I don't have any code expect for the code in above link which is for text box though. Just need an idea of how to do it in asp.net MvC as i cannot move forward now.
Expected results is to do the above requirement, don't have any actual results as of now

iOS Voiceover support for combobox widgets

Typically a combobox widget is an input field that launches an associated popup with a bunch of suggestions in the popup. In desktop browsers using keyboard, while the focus stays with the input field, pressing Up/Down arrow keys, the selection within the popup can be changed. Pressing ENTER key populates the input field with current selection in the popup and closes the popup.
For accessibility purpose, the input field is marked role="combobox", the popup is linked with the input field via aria-owns. The AT are indicated the current selection via aria-activedescendant.
While this setup works great in desktop browsers with tools like JAWS/NVDA etc., there seems to be a major issue with voiceover on iOS. On swiping the finger, the virtual cursor moves to the next element in the page from the input field, though I would expect with aria-owns set, the focus to move to the first suggestion item or to the popup.
Any suggestions on how such a combobox widget can be made accessible in iOS with voiceover?
PS: The popup and input field are not siblings in the DOM order.
It sounds like you are creating a custom combobox. If you use the native <select>/<option> elements, the combobox works correctly on ios/voiceover. If you are creating your own, follow the guidance on https://www.w3.org/TR/wai-aria-practices/#combobox. You mentioned several ARIA attributes so perhaps you're already following the advice on that page.
Swiping right with voiceover will move the focus to the next element in the DOM. If your dropdown list is hidden, then focus won't move to it. Double tapping on your <input> should display the dropdown list.

Value from dropdown on IconTabBar empty

change view (XML) contains IconTabBar with 3 IconTabFilters, which contain input controls (input, combobox, datePicker...). These input controls have pre-filled value from OData model. On the bottom of the view is button "Save". When I click on "Save" button, in my "onSave" function I am reading values from input controls from all IconTabFilters, but only values from the input controls on the first IconTabFilter are filled. Values from the rest of the fields are empty.
When I click on all IconTabFilters (without changing values), click "Save", then I'm getting all values correctly.
Please what I'm doing wrong? Odata model contains all required values, and also IconTabFilters contain all required values. But I can't read them from input controls before clicking on all IconTabFilters.
The Controls on the tabs only get initiated when they have to be displayed. This is done to improve the felt performance of the UI.
Since you are already using model binding, you should take the values out of the model instead of the input fields.

mvc razor default value on httppost for unselected radiobuttons

i have 2 radio buttons , which are optional, so by default no radio button is selected, if the user wants he can select the radio button. But on postback i should check whether the parameter entered by the user are same as the parameters defined in the application, for security.
There are other fields n the screen which are optional like textboxes, but textboxes are getting passed on httppost even when the user does not enter a value it is being passed as empty, but if user does not select radio button nothing is getting passed on postback, that field is missing in httppost.
Any work around to pass default value for unselected radio button on httppost.
You could place a "default" radio button, already selected, but not visible on your site ("style: display: none;"). That's the way ASP.NET works when you use some Html helpers like #Html.CheckBox(...) for instance: it places an invisible second checkbox with the same name, but containing the false value. It assures that a value will always be posted, even if the user doesn't check it (checkboxes, radio, etc are never sent with the form if they are not checked).

How to know which radio button is selected on a view?

I have a created a list view for one of my controller's index action.
I have added a new column "Select This" to this list view, by using the view's source.
The column will contain radio button for each entry in the list. This i have achieved by just placing a radio button control from tool box in the "Select This" column. This i have done in the design of the view and when i run it, i get radio buttons, one for each of the entry. The page also has a link button and i want to call a controller action on this link button click which will receive the index of radio button selected. So if i select 5th radio button, how can receive 5 in the controller action.
How can i do this?
Regards,
kapil
If you used plain HTML, your radio buttons will all have the same name, but different value. You will get one result in the POST, which will contain the selected value.
If you used ASP.net helpers, it's the same, but they will be generated for you: see here: http://msdn.microsoft.com/en-us/library/dd410596.aspx You will pass the same name (first parameter) and different values for each input (second parameter).

Resources