Passing values to form_fields()

edited February 2012 in Modules
Some of my pages load excessively slowly when I insert the fuel edit markers (there are up to 100 of them), but they edit fine from Admin.

Hence, I'm replacing them with simple edit pages. I know how to build the forms essentially manually using form_builder, but it seems that I ought to be able to get some mileage out of the form_fields() function in the model. It builds the form fine if I'm creating a new field, and it populates it fine with existing values if I go at it from Admin, but I've spent all day trying to get it to recognize values that I'm passing from my controller. I look at the chain of parents, and I'm clueless as to what must be wanted for the values -- what I thought was logical, clearly isn't it.

from the model ---
function form_fields($values = array()) { $fields = parent::form_fields($values); $fields['published']['order'] = 1000; return $fields; }

the controller (most recent version of many varients)

$this->load->module_helper(FUEL_FOLDER,'fuel'); $this->load->library('form_builder', array('id'=>'fieldtrip_edit_form','row_id_prefix'=>'id_','textarea_cols'=>'47','form_attrs'=>array('method'=>'post','action'=>'conference/updatefieldtrip'),'submit_value' => 'Save', 'textarea_rows' => '10', 'multi_select_mode'=>'checkbox','single_select_mode'=>'enum')); . . . $this->load->model('conference_fieldtrips_model'); $fieldtrip = fuel_model('conference_fieldtrips', array('find' => 'one', 'where' => 'id = '.$id)); // since type casting didn't do anything desirable, set enough values manually to test $val_arr['id'] = $fieldtrip->id; $val_arr['Title'] = $fieldtrip->Title; $val_arr['Latitude'] = $fieldtrip->Latitude; $fields = $this -> conference_fieldtrips_model->form_fields($val_arr); $data['form'] = $this->form_builder->render($fields);

I have verified that $val_arr gets to form_fields, and I have verified that there are real values in the array.

Any clues?

Or any other thoughts on how to speed up fuel if I use the fuel edit markers? Other than the speed problem, I'd much prefer to be using fuel's tools -- I'm not really in love with needing to add my own validation either ...

Thanks

Comments

  • edited 2:09AM
    This is a different thought on the same subject -- based on what I see, when using the fuel edit markers, the dom takes a horridly long time to load when the number of markers starts to go up. You wait, and wait, and wait, to get them all loaded and the page ready.

    Are you ajaxing these?

    If yes, is there a way to turn off ajax on specific pages?

    Alternatively, is there a way I can throw the links myself and still have fuel handle the actual editing?
  • edited February 2012
    With regards to the values being passed to the form_fields method, the values array is getting to the form_fields method, but you would need to set the values for each field like so:
    function form_fields($values = array()) { $fields = parent::form_fields($values); ...... $fields['published']['value'] = $values['published']; $fields['published']['order'] = 1000; return $fields; }
    The easier method would be to do the following from the controller:
    $this->load->model('conference_fieldtrips_model'); $fieldtrip = fuel_model('conference_fieldtrips', array('find' => 'one', 'where' => 'id = '.$id)); // since type casting didn't do anything desirable, set enough values manually to test $val_arr['id'] = $fieldtrip->id; $val_arr['Title'] = $fieldtrip->Title; $val_arr['Latitude'] = $fieldtrip->Latitude; $fields = $this -> conference_fieldtrips_model->form_fields($val_arr); $this->form_builder->set_fields($fields); $this->form_builder->set_field_values($val_arr); $data['form'] = $this->form_builder->render();
    Note the use of the set_field_values after the set_fields method call on the form_builder object.

    With regards to the inline editing markers, it can indeed take a while for it to render if you have a lot (especially 100+). The main reason is because of the calculations it needs to absolute position the pencil icons so they don't overlap each other. Also, if the window resizes, it needs to recalculate that positioning.

    You can define a constant in your page layout of "USE_FUEL_MARKERS" which will prevent them from rendering. Or you could simply not use the fuel_var function or fuel_edit functions in your layout and just use a straight variable merge like so:
    <?php echo $my_var?>
    Instead of
    <?php echo fuel_var('my_var')?>
  • edited 2:09AM
    Thanks ... I'm going to try those and see which works the best.
  • edited 2:09AM
    I'm having trouble understanding what the last suggestion gets me ...I'm using
    <?=fuel_edit($naturetrail->id, 'Edit Naturetrail', 'naturetrails');?>
    and I clearly do need either a marker or a more blatant link ..

    If the "too much time issue" is due to the math, and if I'm willing to do something like boxing the markers into a fixed location relative to the item or displaying them on an otherwise blank line above the item, why would I not want to just "manually" duplicate the code that is around line 592-601 just hard coding the offsets? I'm assuming I might also need to check if fuelified first so I only show them for those who should see them.

    Thanks
  • edited 2:09AM
    The last suggestion was just to simply turn inline editing off for that page to prevent the slowness which sounds like is not an option for what you are wanting to achieve. When you say line 592-601, what file are you referring to?
  • edited 2:09AM
    Sorry -- Fuel_page.php

    I do need on page editing. I'd greatly prefer it be done via Fuel's in_line editing so that the site stays reasonably self consistent. So far as I can see, the pages reload fine after the save up until time to display the edit markers...then depending on how many there are, I've seen it take up to 5 minutes to get those markers displayed. I'd like in_line edit to work but that I handle the markers/links to edit forms some faster way.

    I have a fair amount of formatting flexibility -- the problem pages are just lists of titles and paragraphs with space between. So, I'm OK with some non-fancy way to provide the edit form links so long as the user experience stays similar (shorter pages are just fine).

    Thanks.
  • edited 2:09AM
    Hmm... I'm not sure if getting 100+ inline editing markers to load quickly is going to be easy to do. The file that does a lot of the inline editing rendering is the fuel/modules/fuel/assets/js/fuel/edit_mode.js and may want to look at disabling the adjustPosition function to see if it speeds things up some.
Sign In or Register to comment.