Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Conditions in a setFieldFormatting

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 2163 Views
  • Ney
    Avatar
    Community Member
    8 Posts

    Conditions in a setFieldFormatting Link to this post

    hello guys I need your help!! I wanna put a condition in a setFieldFormatting of a ComplexTableField but my condition isn't working it is my code:
    $Currency = new ComplexTableField(
          $this,
          'Currencies', // relation name
          'CurrencyP', // object class
          array(
                'Currency_Iso'=>'Currency Iso',
                'Currency_Name'=>'Currency Name',
                'Currency_Symbol'=>'Currency Symbol',
                'Price'=>'Price',
                'Number_Format'=>'Format',
                'Currency_Default'=>'Currency Default',
                "Active_Inactive" => "Active Inactive"
                ), // fields to show in table
          "getCMSFields_forPopup" // form that pops up for edit
          );
                
          
    $Currency->setFieldFormatting(array('Currency_Default'=>'<input type=\"radio\" name=\"default\" value=\"$ID\"'.('$Currency_Default'=='1'?' checked="checked':' ').'>$ID' ));

  • carlossg
    Avatar
    Community Member
    13 Posts

    Re: Conditions in a setFieldFormatting Link to this post

    Hi Ney.

    Did you fix that problem?, i'm dealing with something similar, but much simpler and i got to the point that source fields can't be referred that easy

    $MyTable = new ComplexTableField(
    $this,
    'MyRelationName', // relation name
    'MyObjectClass', // object class
    array(
    'Time'=>'Time_Label',
    'Date'=>'Date_Label',
    ), // fields to show in table
    "getCMSFields_forPopup" // form that pops up for edit
    );

    $MyTable->setFieldFormatting(array('Time'=>$Time)); //obviously i don't want to do this!!

    I want to use php date_format function to reformat time i the ComplexTableField but $Time variable gets NULL.

    Any idea?

    Thanks in advanced.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Conditions in a setFieldFormatting Link to this post

    how about a (kinda presentational) getter on your model instead? its not pretty, but does the job... alternatively you could sublcass ComplexTableField with a custom template.

    class CurrencyP {
    function getCurrencyDefaultChecked() {
    return ($this->Currency_Default) ? 'checked' : '';
    }
    }

    $Currency = new ComplexTableField(
    $this,
    'Currencies', // relation name
    'CurrencyP', // object class
    array(
    'Currency_Iso'=>'Currency Iso',
    'Currency_Name'=>'Currency Name',
    'Currency_Symbol'=>'Currency Symbol',
    'Price'=>'Price',
    'Number_Format'=>'Format',
    'CurrencyDefaultHTML'=>'Currency Default',
    "Active_Inactive" => "Active Inactive"
    ), // fields to show in table
    "getCMSFields_forPopup" // form that pops up for edit
    );
    $Currency->setFieldFormatting(array('Currency_Default'=>'<input type=\"radio\" name=\"default\" value=\"$ID\" checked=\"$CurrencyDefaultChecked\">$ID' ));

    2163 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.