MVC2 Multi Select drop down list - asp.net-mvc-2

I have 2 multi-select Html.DropDownList controls with a button between them. When the user selects items from the first and presses the button they are copied to the second Html.DropDownList control via JQuery.
My problem is when the form is posted back I do not know how to obtain all the values in the second Html.DropDownList control.
This would be really easy with web forms but I have no idea how to do it with MVC2
thanks
--- Also I will need to validate the second Html.DropDownList to ensure it contains at least one item.

Okay, I can get it to work by selecting all the items in the list with JavaScript right before the post back. This feels like such a hack to me though. Surely there is a better way to do it then this. Does anyone know of a way that does not rely on JavaScript?
If relying on JavaScript is the standard way to do this sort of thing then can someone explain why this is okay... Or is this an example of the immaturity of the MVC model?
Thanks.

Related

Backpack crud field that displays an included filtered table

I need to make a new type of field, let's call it included_table. If in Model employees I have a field of type select2 from model Departments, in Departments, I want to have a field of type included_table which displays the table of the employees from that department, in the same way as the crud does.
Is there an easy way of doing this? Or what would be the best way to start?
Thank you.
I don't think there's an easy way to do it. You'd have to code it yourself. You can start from the table field type, put it won't get you very far.
That's because it's a lot more complicated that it looks at first glance. Keep in mind that Backpack create/update forms work with refresh; if you put a table inside one of them, the expected behaviour might be to only "save" the information when you click the final "save" button; but you probably can't do that for the nested entity, because you'd be saving it with AJAX. Plus, you need to build that entire AJAX functionality yourself, including validation. It's not at all more difficult than using plain old Laravel - it's exactly the same. But Backpack won't help very much in this regard.
That being said, you'd probably be better off just putting a button in the list view for each Department, to go edit its employees. That's a lot easier to do, if you follow the nested resources tutorial.
Hope it helps.

SYMFONY FORM - filter attribute form on top with submit button, that provides a table with other form used to edit each row details

I am looking for best practices on SYMFONY FORM handling to achieve the following standard page (surprisingly I haven't found anything similar existing yet on SO).
Here is a shema of what I want to achieve:
As you can see at the top there is a SYMFONY FORM to filter the results that should be displayed.
It displays a table and each tuple of the table should permit to open another SYMFONY FORM kind linked to the tuple.
I am in the process of learning SYMFONY FORM, so far, I can manage to create the top row FORM to set the filter that'll apply to the table display.
But I wonder if anyone has experience on the second part: Displaying the table that embed as well many forms of a similar kind -That seems a bit more complex. I read about TWIG.EXTENSION and FORM.COLLECTION, I'll investigate that. But if someone could save me to re-invent the wheel and lead me to some direct shortcut, I'd be really grateful.
No idea if it's the best practice, but one way to do it would be to create a new property for your entity being listed in this table, called $editionForm (without mapping it to the database) for example.
Then, either throught a custom loop or by listening to a doctrine (or any ORM you use) hydration event (or triggering such an event if you don't use any ORM), fill the property with the generated form, probably within a dedicated service.
Then, just use it in your template like this :
$entity->getEditionForm()->render()

Simulate Form Submit with Symfony 2

I'm working with Symfony 2 and need some advice.
I have a Controller, which gets a form-request and searches the database for matches and renders the results (so it's just a basic search).
Now I would like to redirect to this controller but without coming from a form.
To be more specific:
I'm on the search-page, fill out the form and hit the search button -> I get results for my search.
I'm somewhere else and want to delete a labelCategory of a book -> If some books still use this labelCategory, I want to get search results for this labelCategory.
My only idea so far is, to simulate the form submit somehow, but I didn't find out how to do it.
I'd be happy for every help of you ;)
You don't need form submit at all. Just put logic of searching to separate class. Than you can it in any controller you want. Maybe Service Container doc can help to

What is the best way to present multiple options in a form for section 508?

I will need to provide a way for a user (who will be using a screen reader) to select multiple options within a form. Currently, these options are laid out in a two column table with checkboxes in the first column and spans with the label for the option in the second column. This isn't section 508 compliant, but it will need to be for this site. I'm trying to figure out the best way to replace this form with something better.
The options I have are to either
Use ul/lis with labels for the checkboxes
OR
Use a multi-select drop down list.
Does anyone have a preference or a better idea?
I've decided to use a muli-select dropdown. In case anyone was wondering. It seems to work fairly well with the screen reader I'm using. I did find that IE seems to be the best browser to work with and most screen readers aren't working very well with Chrome or other browsers unfortunately. I can only assume then that most people who visually disabled are probably using IE because of this.

Pattern for Spring-MVC stateful interaction

Today I was doing this thing with Spring:
Have a page with a form and a chance to choose one item related to the form.
If you push "Choose item" the app will save somehow what you typed in the form, go to another page, let you choose the thing.
When you are back to the form it's filled with what you wrote before going to the other page, plus the item chosen.
Seems easy, but you have to take into account that for some stupid reason the user could open the page where you choose the item (maybe because of a bookmark, or because he pressed the back button 10 times to play). You know what I mean. I tried many ways, mainly based on HttpSession... I don't like any of those. None of them seems elegant. I was even thinking of using a hidden form in the other page, but given that it is not unique to this "flow" (I mean you can go to the item choose page from others as well), I will have to worry about conflicts and so on.
So what would be the preferred way for you? Suggestions?
Go around the problem instead of solving it. You can use a modal javascript div popup where the user can pick the item she wants. The contents of this div can be loaded via ajax (separate Spring MVC controller called with Http GET). Once the selection has been made, you close the popup (hide the div) and copy the value into the original form. Done.
No need to store the state anywhere.
I suggest Spring Web Flow.
Spring Web Flow compliments the Spring MVC.
Here is link to Spring Web Flow Demo