I am using community edition of Pyrocms, so cant really use the benefit of stream module that comes in pro edition. I am trying to work with Stream API.
I have defined a stream field's meta data as below:
$field = [
'name' => 'First Name',
'slug' => 'first_name',
'namespace' => 'users',
'type' => 'text',
'extra' => array(
'max_length' => 50,
'placeholder'=> 'Enter your first name' //NOT WORKING
),
'assign' => 'profiles',
'required' => true
]
$this->streams->fields->add_fields($fields);
In the above code, I have declared a key placeholder
inside extra
and have written its value. But when I later use this stream-field in the form by echoing out as
<?php echo $field['input']; ?>
Input field is rendered as expected and the validation is also working but the text for placeholder does not appear. Same is the case when I try to add extra class attributes when defining meta data for field. I have had a good look in pyrocms documentation. It says there is a way to define attributes for rendered input but have not shown how to do it. I tried adding it into extra
also tried defining outside the extra
but still I am not able to show up the extra attributes for the input fields. Also, when the type is set to choice, where should I put the default value for drop down menu or checkbox?
The field type 'text' doesn't have a parameter 'placeholder', only 'max_length' and 'default_value'.
So you could copy the text field type, rename the folder and the class, place it in addons/default/field_types and add this parameter to the field type - basically writing your own field type. It's really easy and I made a gist for you: https://gist.github.com/marcogrueter/02b5e70f02402d999059