Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fieldset class issue
  • Hi, I have been looking at the Fieldset class and have come across a small issue. The call to Form::factory in fieldset.php line 156 is passing $this but the form class has changed and is now expecting an array.
  • Issue with validation not working as well Temporary Fix: fieldset.php lines 132 through to 160 - comment out the passing of $this.
    /**
      * Get related Validation instance or create it
      *
      * @return Validation
      */
     public function validation()
     {       
      if (empty($this->validation))
      {       
       $this->validation = Validation::factory($this->name); //, $this);
      }
    
      return $this->validation;
     }
    
     /**
      * Get related Form instance or create it
      *
      * @return Form
      */
     public function form()
     {       
      if (empty($this->form))
      {       
       $this->form = Form::factory($this->name); //, $this);
      }
    
      return $this->form;
     }
    

    Now just got to work out how to format the output as it is all displayed on one line at the moment :-) Good job on the fieldset class it makes life a lot easier. Just thinking about how to enable the set_form_fields call to also accommodate the new viewmodel class so it can appear in either model or viewmodel.
  • I'll look into this shortly, for the future: make bug reports on either Github or dev.fuelphp.com - that's where we look which bugs need fixing. The forums are for community support.
    Good job on the fieldset class it makes life a lot easier. Just thinking about how to enable the set_form_fields call to also accommodate the new viewmodel class so it can appear in either model or viewmodel.
    To be honest, this doesn't make sense. ViewModels and Models are completely different: ViewModels are about preparing data for a template and seperating the view logic from the controller or view where it shouldn't be. Models are about CRUD operations on data.
    As far as I'm concerned a Fieldset definition is Model specific (it relates to editing) and not view specific (it doesn't relate to formatting or displaying).
  • Hi, Sorry. I miss-understood what you had developed ViewModels for I thought it was to add another layer to views. The way I understood it was a ViewModel was an additional place to build stuff to display in the View like a form for example. I understand now though thanks.
  • These 2 things about ViewModels are correct:
    I thought it was to add another layer to views.
    The way I understood it was a ViewModel was an additional place to build stuff to display in the View

    However the Fieldset::add_model() method for adding things through a Model method set_form_fields() is meant so you can describe your from in a centralized location to use in multiple views. If you want to use a ViewModel to build a form, there's nothing against that but as a ViewModel maps directly to a View there's no use in what you're proposing. A ViewModel is not a centralized location to use with multiple views, it is a very specific class for generating the data for one specific View.
  • Hi, Yes I stopped and thought about it and then it made sense to have the form definition in the Model. I like the Fieldset class but can't seem to find how to control the output as it is currently all displayed on one line so any help or example here would be appreciated. Thanks.
  • The issue with the form() and validation() methods of Fieldset has been solved.
  • Jelmer, Thank you I will have a look later. Did you also do anything about controlling the layout ie. the ability to add a <br /> at the end of the <input blah blah><br /> or enclose the <label> <input> in a <p> </p> as I didn't see how I could achieve that when I last looked at the code. Thanks again for the fix much appreciated.
  • Hi,
    Did you also do anything about controlling the layout ie. the ability to add a <br /> at the end of the <input blah blah><br /> or enclose the <label> <input> in a <p> </p> as I didn't see how I could achieve that when I last looked at the code.

    The answer is to create a form.php in app/config
    return array(
        //'required_mark'      => '<span class="required">*</span>',
        'field_template'        => '{label}{field}<br />',
        'multi_field_template'  => '{label}{field}<br />'
    );
    

    Note: Do not have any spaces between the {and label and {and field the forum preview has inserted them. Then format it further with css.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion