I'm implementing a registration form in Grails with a bit of Ajax. My goal is to display a radio group of three options and based on the selection, the relevant domain fields will appear below.
I have three domain objects: an User, Donor and Teacher. A User can be a Donor, Teacher or both, thus the reason for a wrapping object.
All the examples I've seen with multiple selections from a list or radio group deal with different instances of the same domain class. Is it possible to do this with multiple domain objects?
Create 3 templates for each domain class and based on the value of your select or radio button render the correspondent template.
Check this out: AJAX Driven SELECTs in GSP
Maybe can solve your issue
Related
I want to split Devise user into different types? Like, for example: user go to the registration page and sign up, but based on whether they're a teacher or a student they will registered and login to see different navbar? How would I do that using a checkbox?
It is excellently explained in their Wiki.
In my opinion you should consider option number 1. and 3:
Separate model for student and teacher, if they have different attributes
One model for both with additional column role. It will be appropriate if models have the same attributes.
Then on your views just check what is the role / type of user and present proper content.
I'm trying to create a Create page for a slightly complex 'view model'/view setup that I'm looking for.
Imagine I have two entities -
Person
-PersonID
-Name
-Height
-Nationality
And that Person can have multiple Addresses - here's the Address entity:
Address
-PersonID
-AddressDescriptor
-FirstLine
-SecondLine
-City
-ZipCode
Now in my Person Create view I want the user to be able to enter the person details,
and then add as many addresses as they like.
I'm visualizing this as something like a set of text boxes for both the person and the address area. Followed by an add button for the address. When clicked this add button would add the address to a grid of added addresses. The grid would also have options for delete/edit.
Finally there would be a submit button to save the person and address records to the database.
What is my best bet for achieving something like this.
Should I be looking to use partial views for the grid / rendered by AJAX calls back to the controller? If so could someone point me to a modern example of doing this - using Razor if possible?
This runs through the basic principles of what you are trying to achieve:
http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/
You could create an action that accepts AJAX posts to add the user. Just create a jQuery function that will create your form when they click "add address" and on submit, another jquery ajax call to post to your controller action.
I'm posting this question because I do not know the best/correct way of doing the following.
My team-mate (the designer) sent me a good looking design that includes a wizard for adding new items (for auction). The user has to fill in all the required details which include the title, description, starting price...etc AND a list of tags (up to 4 tags - chosen from the database, will use auto complete) as well as a list of up to 3 images/youtube url's (for the sake of better explanation check this image out: http://i55.tinypic.com/2v11zzr.png)
Ok so I figured out how I should do the wizard ( reference: how to make a wizard with ASP.Net MVC) but I'm not sure about how to collect the lists and the images/url's. Here's what I'm thinking:
For the images/url's, I should create a parent view model from which two sub-classes (ImageViewModel & YoutubeUrlViewModel) would inherit from and then in the controller action when I parse the post data, I would check to see the instance of the parent view model and act accordingly.
Now about the lists, I'm not sure whether I should include a List in my view model or whether I should include 4 string properties representing the tags (the same will apply to the list of images/url's).
So what's the best way of doing this?
And Haacked to the rescue: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx
:)
I have a typical HABTM relationship between members (actual members of our organization, not all have online accounts) and users (online accounts). I have an edit users page for site administrators where multiple members can be assigned to users.
There are too many members to reasonably use checkboxes or a multi-select dropdown. I have decided to use dropdowns that are added by clicking an "Add Member" button that uses an AJAX function to add a dropdown.
Here's what I have working:
I can add dropdowns and pick any member. On save, the relationships are established.
I can edit that user and add more members, remove members, and change members in the dropdown.
The final piece I am struggling with is having my remove link (next to each member drop down) remove a drop down for a new user. The reason being that the action behind the remove link relies on the id of the div that contains the dropdown. When editing a user, this id is generated based on the selected member. For a new user, I do not know the selected member in the dropdown, so I can't assign it an id that I can know about when the remove link is clicked.
Are dropdowns the way to go? Are there any good tutorials or examples of what I am describing out there? Should I perhaps update the div ID in an onchange event in the dropdown?
I have found that the best way to do this is to use the object_id of member to create a unique div id. My Javascript function is then able to use this to remove the div.
I have an asp mvc 2 app lication where I want to display a list of check boxes that a user can select, based on a list of records in a database. To display the list my model contains a List object and the view has a foreach, and outputs Html.CheckBox for each item in the list.
Is there a way to get the model populated with the selected checkboxes, given that the model can't have specific properties for each checkbox, because the list is dynamic? Or do I have to manually iterate through the forms variables myself?
Edit: Extra details as per sabanito's comment
So in a simple view/model scenario, if my model had a property called Property1, then my view outputted a Textbox for Property1, when the form is posted via a submit button, the mvc framework will automatically populate a model with Property1 containing the text that was entered into the textbox and pass that model to the Controllers action.
Because I am dealing with a dynamic list of options the user could check, I can't write explicit boolean properties in my model and explicitly create the checkboxes in my view. Given that my list is dynamic, I'm wondering if there are ways to create my model and view so that the mvc framework is able to populate the model correctly when the form is posted.
Here's what I would do:
Are you having any issues generating the checkbox's dynamically?
If not, create a property on your ViewModel that is a:
public List<string> CheckboxResults { get; set; }
When you generate your checkbox's in the view make sure they all share the name = "CheckboxResults". When MVC see's your ViewModel as a parameter on the action method it will automatically bind and put all the "CheckboxResults" results in the List (as well as your other ViewModel properties). Now you have a dynamic List based on which checkbox's your user checked that you can send to your DomainModel or wherever.
Pretty cool stuff. Let me know if you're having issues generating the checkbox's dynamically, that's kind of a seperate issue than model binding to a list.
Use a ViewModel that reflects your view exactly, and map your domain model(s) to the viewmodel.
At first it often seems appropriate to use domain models directly in the view, for no better reason than that they're simple to use. However, as the view gets more complex over time, you end up putting a TON of conditional logic in your view, and end up with spaghetti. To alleviate this, we typically create a ViewModel that correlates 1:1 with the view.