formbuilder

Trying to extend ActionView::Helpers::FormBuilder

泄露秘密 提交于 2019-12-01 07:47:17
问题 I am trying to DRY up some code by moving some logic into the FormBuilder. After reading the documentation about how to select and alternative form builder the logical solution for me seemed to be something like this. In the view <% form_for @event, :builder => TestFormBuilder do |f| %> <%= f.test %> <%= f.submit 'Update' %> <% end %> and then in app/helpers/application_helper.rb module ApplicationHelper class TestFormBuilder < ActionView::Helpers::FormBuilder def test puts 'apa' end end end

How do I pass an array to fields_for in Rails?

∥☆過路亽.° 提交于 2019-12-01 05:12:07
问题 I want to use fields_for on a subset of records in an association. I have a Month model, which has_many :payments . But in my form in my view I only want to have fields_for some of those payments. For example: - fields_for @month.payments.large This doesn't work. Can I pass a set of records to fields_for , rather than the usual symbol ( fields_for :payments ) approach? 回答1: You can add additional association for large payments, for example: class Month < ActiveRecord::Base has_many :payments

how to get doctrine repository in form type class in symfony2?

南笙酒味 提交于 2019-12-01 03:24:28
问题 $repository = $this->getDoctrine()->getRepository('ParabolaEntityBundle:ProjectAllocation'); $query = $repository->createQueryBuilder('p') ->where('p.startDate < :sdate and p.employee = :emp and p.endDate > :edate') ->setParameter('sdate', date('Y-m-d', time())) ->setParameter('edate', date('Y-m-d', time())) ->setParameter('emp', $employee->getId()) ->getQuery(); $projectAllocate = $query->getResult(); how can i use above code in FormType class.I am using this query to generate array for the

Passing ActionView::Helpers::FormBuilder to a partial

拟墨画扇 提交于 2019-11-30 20:21:40
I am atempting to dinamically create form elements given a certain AJAX request. This is my setup: View: <%= link_to 'Next', check_unique_id_students_path, :remote => true %> <div id="guardian_student_details"></div> Controller: def check_unique_id @student = Student.new @this_form = ActionView::Helpers::FormBuilder.new(:student, @student, @template, {}, proc{}) end JS: jQuery("#guardian_student_details").html("<%=escape_javascript(render :partial => "student_details", :locals => { :s => @this_form }) %>"); Partial: <% puts s.text_field :first_name %> <% puts s.field_helpers %> For debugging

Symfony2 how to render Checkboxes?

梦想的初衷 提交于 2019-11-30 15:49:14
I have a formbuilder form with a multiple choice list of countries. When I render them on my form like this: {{ form_widget(edit_form.countries) }} They appear like this: <input type="checkbox" name="..." value="AD" /><label for="...">Andorra</label> <input type="checkbox" name="..." value="AE" /><label for="...">United Arab Emirates</label> <input type="checkbox" name="..." value="AF" /><label for="...">Afghanistan</label> I would like each option displayed on it's own line in the browser, instead of all in a row. How can I inject html around or between the options? Or is there a CSS method

Angular2: Conditional required validation

懵懂的女人 提交于 2019-11-30 13:09:48
I am trying to create a conditional required validation on a specific field.I try doing this by return Validators.required back in my function, but this doesn't seem to work. How do I go about doing this? Here's my code: private _ansat: AbstractControl = new FormControl('', Validators.required); private _helbred: AbstractControl = new FormControl('', Validators.compose([this.useValidateIfRadio(this._ansat, 0, Validators.required)]) ); constructor(private _fb: FormBuilder) { this.myForm = this._fb.group({ ansat: this._ansat, helbred: this._helbred }); } useValidateIfRadio (c: AbstractControl, n

Angular2 FormBuilder: Using 'this' in a custom validator

限于喜欢 提交于 2019-11-30 09:21:05
问题 I'm developing a form using Angular2's FormBuilder with custom validation. Problem: In customValidator I'm using this to access the local object data . I'm getting a undefined error when the validation is executed. It looks like the customValidator is executed in a different object and therefore changing the this reference Question: How can I pass a reference of this to the customValidator? export class Ast { public data:any; public myForm:FormGroup; constructor(private _fb:FormBuilder) {

Passing ActionView::Helpers::FormBuilder to a partial

六眼飞鱼酱① 提交于 2019-11-30 03:56:51
问题 I am atempting to dinamically create form elements given a certain AJAX request. This is my setup: View: <%= link_to 'Next', check_unique_id_students_path, :remote => true %> <div id="guardian_student_details"></div> Controller: def check_unique_id @student = Student.new @this_form = ActionView::Helpers::FormBuilder.new(:student, @student, @template, {}, proc{}) end JS: jQuery("#guardian_student_details").html("<%=escape_javascript(render :partial => "student_details", :locals => { :s =>

Symfony2 how to render Checkboxes?

自闭症网瘾萝莉.ら 提交于 2019-11-29 22:55:36
问题 I have a formbuilder form with a multiple choice list of countries. When I render them on my form like this: {{ form_widget(edit_form.countries) }} They appear like this: <input type="checkbox" name="..." value="AD" /><label for="...">Andorra</label> <input type="checkbox" name="..." value="AE" /><label for="...">United Arab Emirates</label> <input type="checkbox" name="..." value="AF" /><label for="...">Afghanistan</label> I would like each option displayed on it's own line in the browser,

Angular2: Conditional required validation

末鹿安然 提交于 2019-11-29 18:28:52
问题 I am trying to create a conditional required validation on a specific field.I try doing this by return Validators.required back in my function, but this doesn't seem to work. How do I go about doing this? Here's my code: private _ansat: AbstractControl = new FormControl('', Validators.required); private _helbred: AbstractControl = new FormControl('', Validators.compose([this.useValidateIfRadio(this._ansat, 0, Validators.required)]) ); constructor(private _fb: FormBuilder) { this.myForm = this