Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Userforms Container field


Go to End


3 Posts   970 Views

Avatar
helenclarko

Community Member, 166 Posts

4 November 2014 at 4:33pm

Im not sure where this module/addon came from, but I used it with SS 2.4 and now with upgrading to SS 3.1 I am unable to get it to work.
I was hoping someone was able to take a look at it for me.

EditableCompositeField.php

<?php

class EditableCompositeField extends EditableFormField {

	static $singular_name = 'Container Field';
	
	static $plural_name = 'Containers';
	
	static $has_many = array(
		"SubFields" => "EditableFormField"
	);
	
	function getFormField() {
		$children = $this->SubFields();
		$field = new CompositeField();
		if($children && $children->exists()) {
			foreach($children as $child) {
				$field->push($child->getFormField());
			}
		}
		return $field;
	}
	public function IsContainer(){return true;}
}

There also seems to be some modifications within CSS

FieldEditor.css

		/** Container Fields **/
		
		#Fields_fields .EditableCompositeField ul.subFieldsList {
			min-height: 20px;
			padding-bottom: 10px;
			background: #f4f4f4;
			display: block;
			clear: both;
			margin-left: 38px;
		}
			#Fields_fields .EditableCompositeField ul.subFieldsList li {
				display: block;
				margin: 0 2px 0 7px;
				padding-left: 10px;
				background: white;
			}

and addition to EditableFormField.ss

	<% if IsContainer %>
		<ul class="subFieldsList ContainerField{$ID}">
			<% if SubFields %>
				<% control SubFields %>
					$EditSegment
				<% end_control %>
			<% end_if %>
		</ul>
	<% end_if %>

Is it possible to create a container field within SS3.1?
I seem to be missing something, adding these additions into the SS 3.1 userforms module and fixing depreciation didnt seem to work too well.
I was unable to drag onto the container field.

Avatar
helenclarko

Community Member, 166 Posts

6 November 2014 at 3:08pm

Edited: 06/11/2014 3:12pm

UPDATES:

EditableCompositeField:

<?php

class EditableCompositeField extends EditableFormField {

	private static $singular_name = 'Container Field';
	
	private static $plural_name = 'Containers';
	
	private static $has_many = array(
		"SubFields" => "EditableFormField"
	);
	
	public function getFormField() {
		$children = $this->SubFields();
		$field = new CompositeField();
		if($children && $children->exists()) {
			foreach($children as $child) {
				$field->push($child->getFormField());
			}
		}
		return $field;
	}
	public function IsContainer(){return true;}
}

EditableFormField.ss
   <% if IsContainer %>
      <ul class="subFieldsList ContainerField{$ID}">
         <% if SubFields %>
            <% loop SubFields %>
               $EditSegment
            <% end_loop %>
         <% end_if %>
      </ul>
   <% end_if %>

There seems to have been some Javascript modifications made too, but locating the differences between 2.4 and 3.1 is difficult.

Avatar
helenclarko

Community Member, 166 Posts

13 November 2014 at 11:38am

Any help is appreciated.