Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add form elements dynamically with ajax #57

Closed
gpassarelli opened this issue Jan 24, 2013 · 6 comments
Closed

Add form elements dynamically with ajax #57

gpassarelli opened this issue Jan 24, 2013 · 6 comments

Comments

@gpassarelli
Copy link

Hi there, this is more a questions than an issue.
I'm trying to append form elements to my form dynamically through ajax, the idea is that the user can add many options of this field as he/she wants.
So I don't need to open another form tag for these elements because I'll append to inside an existing form. But the problem is when I create my form elements in another page, that I'll load through ajax, the form elements doesn't render properly if I don't user the Former::open() function.

There is/are any thing I can do to the form elements render properly without need to call the function Former::open();

Hope my question make sense, sorry for my english

@Anahkiasen
Copy link
Member

Well that's actually more of a Bootstrap problem than a Former one : Former automatically creates the correct Bootstrap syntax to have fields all in the right places but in Javascript I don't really know how you could make them render properly without using all the control group syntax : http://twitter.github.com/bootstrap/base-css.html#forms

@gpassarelli
Copy link
Author

I see, but what happens is that without creating the Former::open() the group syntax is not created for the field. The output for the following code is:

{{Former::mini_text('visa_value[]','visa_value')->prepend('$')->required()->class('span9')->value($visa_option->value)}}
    <label for="visa_value[]">Valor<sup>*</sup></label>
    <input class="span9" required="true" type="text" name="visa_value[]" id="visa_value[]">

when was supposed to be:

<div class="control-group required">
  <label for="visa_value[]" class="control-label">Valor<sup>*</sup></label>
  <div class="controls">
    <div class="input-prepend">
      <span class="add-on">$</span>
      <input class="span9" required="true" type="text" name="visa_value[]" id="visa_value[]">
    </div>
  </div>
</div>

That's why I thought could be a Former issue for not generating the control group syntax.

@Anahkiasen
Copy link
Member

Now that's normal, by default fields outside of a form are considered inline because most of the time when you put fields outside of forms it's in random places, tables and stuff. This is kind of one of the tricky parts of Former.

I don't think there's a way to add the control group for a specific field outside of a form. You can do the opposite (remove the group with ->raw) but there's nothing yet to add a group where there isn't supposed to be one. Maybe if you have a suggestion of way to handle that I could implement it ?

@gpassarelli
Copy link
Author

That's right, make sense.

I can try to think in a best way, but the way that just poped in my mind,
could be something the same way that you define the size of the field, for
example

Former::mini_text(...);

You can set also if you want in a group control, something like:

Former::grouped_mini_text(...);
Former::group_mini_text(...);

Or any other word that make more sense.

@Anahkiasen
Copy link
Member

Hm this is not bad, I'll think about it see what I come up with.

@gpassarelli
Copy link
Author

OK, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants