block_name problem

edited August 2014 in Bug Reports
two blocks

// Fuel layout block
$block = new Fuel_block_layout('about_article_block');
$block->set_label('About article');
$block->add_field('title', array());
$block->add_field('anchor', array());
$block->add_field('content', array('type' =>'text'));
$block->add_field('social', array('label'=>'Social sharing','type' =>'checkbox', 'value'=>1));

$config['blocks']['about_article_block'] = $block;

$block = new Fuel_block_layout('about_related_article_block');
$block->set_label('About elated article');
$block->add_field('article_title', array('label'=>'Title'));
$block->add_field('article_link', array('label'=>'Link', 'ignore_representative' => TRUE));
$block->add_field('article_img', array('type' =>'asset','label'=>'Image',));

$config['blocks']['about_related_article_block'] = $block;

then i specify a layout with above blocks.

$layout = new Fuel_layout('about');
$layout->add_fields($common_fields);
$layout->add_fields(
array(
'banner'=>array('type'=>'asset'),
'banner_text'=>array('type'=>'text'),
'sections'=>array(
'type'=>'template',
'display_label'=>FALSE,
'label'=>'Sections',
'add_extra'=>FALSE,
'repeatable'=>TRUE,
'max'=>6,
'min'=>1,
'title_field'=>'block',
'fields'=>array(
'section'=>array('type'=>'section', 'value'=>'Section {num}'),
//'block'=>array('type'=>'block','folder'=>'sections'), if specify folder will only display blocks under that folder
'block'=>array('type'=>'block'),
),
),

'related_articles' => array('type' => 'fieldset', 'label' => 'Related Articles', 'class' => 'tab'),
'r_articles'=>array(
'type'=>'template',
'display_label'=>FALSE,
'label'=>'Related Articles',
'add_extra'=>FALSE,
'repeatable'=>TRUE,
'max'=>2,
'min'=>1,
'title_field'=>'article',
'fields'=>array(
'section'=>array('type'=>'section', 'value'=>'Related Article {num}'),
'block'=>array('type'=>'block', 'block_name'=>'about_related_article_block','display_label'=>FALSE),
),
),
)
);


please note of 'block'=>array('type'=>'block', 'block_name'=>'about_related_article_block','display_label'=>FALSE), four lines above, once i set the block_name to force the article tab to show only the related field of about_related_article_block, everything go haywire.

What is happening now is it does dislay all the fields. however if i save it. It will auto loop the fields section up to 4 times despite the max set to 2 and i did not add any repeatable section for this tab.

but if i removed block_name to change back to drop down select style, there will NOT have any problem when saved.

very weird behavior to me, any helps?

Comments

  • edited 3:56PM
    When a block_name is specified, the field behaves a little bit differently. With the dropdown select, it will dynamically generate the field information with an ajax call to the fuel/block/layout_fields and pass a "context" value. When you specify a block name, you must also specify the context value. Note that if you inspect the field type names for that block, they are missing the repeatable index number to create the proper array when saved. To fix this, try adding the following as a parameter to your block field:
    'context' => 'r_articles[0][block]'
  • edited August 2014
    I dont get this, where can i add this param?block'=>array('type'=>'block', 'block_name'=>'about_related_article_block','display_label'=>FALSE)? this is a repeatable block which we can add by click the "add more" button, i dont think i can pass a static 0,1,2,3, values to the block
  • edited 3:56PM
    Add this to your fields array for r_articles:
    'block'=>array('type'=>'block', 'block_name'=>'about_related_article_block','display_label'=>FALSE, 'context' => 'r_articles[0][block]'),
  • edited 3:56PM
    i checked this solution, but there are some other side effects. For example, if there is an asset field in the block such as

    $block = new Fuel_block_layout('whatsnew_article_block');
    $block->set_label('Whatsnew');
    $block->add_field('title', array('label'=>'Title'));
    $block->add_field('description', array('label'=>'Description'));
    $block->add_field('link', array('label'=>'Link','ignore_representative' => TRUE));
    $block->add_field('tag', array('label'=>'Tags', 'type'=>'checkbox'));
    $block->add_field('cover_img', array('type' =>'asset','ignore_representative' => TRUE));
    $config['blocks']['whatsnew_article_block'] = $block;


    $layout->add_fields(
    array(
    'whatsnew'=>array(
    'type'=>'template',
    'display_label'=>FALSE,
    'label'=>'Sections',
    'add_extra'=>FALSE,
    'repeatable'=>TRUE,
    'min'=>1,
    'title_field'=>'block',
    'fields'=>array(
    'section'=>array('type'=>'section', 'value'=>'Section {num}'),
    'block'=>array('type'=>'block','block_name'=>'whatsnew_article_block','display_label'=>FALSE, 'context' => 'whatsnew[0]block]'),
    ),
    ),
    )
    );
    $layout->set_label('Whats New Home');
    $config['layouts']['whatsnew_home'] = $layout;



    the "Asset" types will not shown ( only show normal input text field with upload and select button) if include the 'block_name'=>'whatsnew_article_block','display_label'=>FALSE, 'context' => 'whatsnew[0]block]'

    i done some check and discover that the id of the "asset"field will be same as the repeated block "asset" field if click "add more", and the styles are same too

    And if i remove 'block_name'=>'whatsnew_article_block','display_label'=>FALSE, 'context' => 'whatsnew[0]block]' and allow the drop down select the block, asset field will shown without any problem.
  • edited 3:56PM
    That's a bug that I just pushed a fix for in the develop branch:
    https://github.com/daylightstudio/FUEL-CMS/commit/c315747b4383807424207bee89af7301485e9af6
  • edited September 2014
    Thanks a lot, but seem there are another error. In this block, now i set $tag_options=array('must-haves'=>'Must-Haves','exclusives'=>'Exclusives','videos'=>'Videos');
    $block->add_field('tag', array('label'=>'Tags', 'type'=>'multi','mode'=>'checkbox','options'=>$tag_options,'default'=>array()));

    when i saved first block and click add another, the multi checkbox of tag already checked with values from first block, it does not reset to empty.
  • edited 3:56PM
    This should be fixed in the develop branch now.
  • edited 3:56PM
    it seems the add all button is not triggering the jquery.repeatable.js as there are not changes happening. even i do

    $(document).on('click', '.' + options.addButtonClass, function(e){
    e.preventDefault();
    e.stopImmediatePropagation();
    alert('data');
    });

    no alert when i click the button
  • edited 3:56PM
    If you are making change to the jquery.repeatable.js file they won't be seen unless you do one of two things:

    1. Go to the fuel/modules/fuel/config/fuel.php file and uncomment all the js files currently commented out in the $config['fuel_javascript']. Then comment out the 'fuel' => 'fuel/fuel.min'.
    2. Go to fuel/build and it will recompile the CSS and JS files (will take a few seconds).
  • edited 3:56PM
    strange method two is not working
  • edited 3:56PM
    What are you seeing instead? It should go to a white page with some text outputted on it.
  • edited 3:56PM
    It does said new fuel.min.js script is generated, but I did not see the change. Although method one work perfectly but I believe minimized fuel.min.js is better for loading
  • edited 3:56PM
    if you look at fuel.min, are you able to see the changes you made to the jquery.repeatable.js file?
  • edited September 2014
    i searched but cant find the code, most probably converted to short hand syntax?
  • edited 3:56PM
    Possibly. You may need to look for things nearby that don't normally get converted like say for example the repeatableSelector property string value of '.repeatable_container' and then search.
Sign In or Register to comment.