Two model form, adding group of fields with javascript
fieldsformjavascripttabular data
Hi!
I’m new to yii.
To keep everything simple, i have two models, events and contests.
Event can contain one or more contests. While creating or updating event, i should be able to add multiple contests.
It might be a bit javascript specific question, but how do i add more fields with javascript (jquery)? I need to add numeric index to field name, like code example below:
- <input size="45" maxlength="45" name="Contest[0][name]" id="Contest_name" type="text" />
- <input size="45" maxlength="45" name="Contest[0][trials]" id="Contest_trials" type="text" />
- <input size="45" maxlength="45" name="Contest[1][name]" id="Contest_name" type="text" />
- <input size="45" maxlength="45" name="Contest[1][trials]" id="Contest_trials" type="text" />
<input size="45" maxlength="45" name="Contest[0][name]" id="Contest_name" type="text" /> <input size="45" maxlength="45" name="Contest[0][trials]" id="Contest_trials" type="text" /> <input size="45" maxlength="45" name="Contest[1][name]" id="Contest_name" type="text" /> <input size="45" maxlength="45" name="Contest[1][trials]" id="Contest_trials" type="text" />
Is there any simple way to add more empty fields? I could use jquery clone(), but it is not solving index problem.
Possibly related Questions
-
yii-user-management
July 3, 2012 By unknownFreq 1 Answer
-
Related data additional attributes in form
December 3, 2011 By bigardusklei 2 Answers
TAGS
actioncreate ( x 2 )ACTIVERECORD ( x 4 )AJAX ( x 10 )ajaxSubmitButton ( x 4 )AR ( x 2 )cactivedataprovider ( x 2 )CActiveForm ( x 2 )cactiverecord ( x 2 )CGridView ( x 14 )CJuiAutoComplete ( x 3 )CJuiDialog ( x 8 )CListView ( x 8 )controller ( x 7 )Css ( x 2 )CStarRating ( x 2 )CTreeView ( x 2 )database ( x 5 )dialog ( x 2 )dropdownlist ( x 3 )EGMaps ( x 3 )extension ( x 3 )file ( x 2 )form ( x 6 )Giix ( x 2 )gridview ( x 2 )html ( x 2 )javascript ( x 3 )many_many ( x 4 )merge ( x 2 )model ( x 4 )Modules ( x 3 )multilanguage ( x 2 )php ( x 2 )redirect ( x 4 )Registration ( x 3 )relations ( x 5 )renderPartial ( x 8 )session ( x 2 )sorting ( x 3 )sql ( x 4 )url ( x 3 )urlManager ( x 3 )validation ( x 3 )yii ( x 11 )YiiAnswers Site ( x 4 )This website counts Questions and 429 Answers by 7571 registered users.

The index problem you will solve it with the length of selected objects [I recommend you to use DUMMY CLASS for your HTML tags]:
// totally untested // using class instead to get lenghts (inputs inserted) var idx = $('.contest_name_input').length; var $el = $('#Contest_name').clone(); // change id for dummy one $el.attr({id:'DUMMY',name:'Contest['+idx+'][name]'}); $el.val(''); $el.appendTo('#LAYERTOAPPEND').val('');By toni · 393 days 12 hours 38 mins ago
Questions: 0 Accepted: 0 ( 0% ) | Reputation: 0
Hi! Thank you for answering, but I already made an ajax based solution for this and it's working great.
By rang501 · 393 days 9 hours 39 mins ago