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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Validation/RequiredFields & DataObjectManger Module


Go to End
Reply


3 Posts   1965 Views

Avatar
Diomedes22

Community Member, 1 Post

13 October 2009 at 4:21am

Dear Reader,

Let me first start with the fact that I am very new to SilverStripe. Before getting myself into all kind of troubles I started of reading the Tutorials, and heard about this Module for SilverStripe by a Colleague.

It all seemed to work fine, until i wondered how to do validating with the DataObjectManager_Popup Form. Some strange things seem to happen over there! We noticed some other people asked for a solution, but from my point of view there wasn't one yet.

First post i found: link 1
Second post i found: link 2

We worked on figuring how to make it work, and voila:



class Person extends DataObject {
	
	static $db = array(
		"FirstName" => "Varchar(40)",
		"LastName" => "Varchar(40)",
		"Gender" => "Enum('Man, Vrouw','Man')",
		"DateOfBirth" => "Date",
		"Description" => "HTMLText"
	);

	static $has_one = array('PersonHolder' => 'PersonHolder');
	
	public function getCMSFields_forPopup(){
		
		$fieldSet = new FieldSet(
			new TextField('FirstName', 'Voornaam','','40'),
			new TextField('LastName', 'Achternaam', '','40'),
			new DropdownField('Gender', 'Geslacht', array('Man', 'Vrouw')),
			new CalendarDateField('DateOfBirth','Geboorte Datum'),
			new HtmlEditorField('Description','Beschrijving')		
		);
		
		$fieldSet->changeFieldOrder(array(
			'FirstName', 
			'LastName', 
			'Gender', 
			'DateOfBirth', 
			'Description'
		));
		
		return $fieldSet;

	} 
	
}


class PersonHolder extends Page {

	static $db = array();
	
	static $has_many = array(
		"Persons" => "Person"
	); 
	
	public function getCMSFields(){
		$oDOM = new DataObjectManager(
			$this,
			'Persons',
			'Person',
			array(
				'FirstName' => 'Voornaam',
				'LastName' => 'Achternaam',
				'Gender' => 'Geslacht',
				'DateOfBirth' => 'Geboorte Datum',
				'Description' => 'Beschrijving'
			),
			'getCMSFields_forPopup'
		);
		$oDOM->popupClass = 'PersonDataObjectManager_Popup';

		$fields = parent::getCMSFields();
		$fields->addFieldToTab('Root.Content.Persons', 
			$oDOM
		);
		
		return $fields;
		
	}	
}

class PersonHolder_Controller extends Page_Controller {
	
}

class PersonDataObjectManager_Popup extends DataObjectManager_Popup {
	function __construct($controller, $name, $fields, $validator, $readonly, $dataObject) {
		parent::__construct($controller, $name, $fields, $validator, $readonly, $dataObject);
		$oVal = new RequiredFields(array('FirstName', 'LastName'));
		$oVal->setForm($this);
		$this->validator = $oVal;
	}
}

Avatar
splatEric

Community Member, 15 Posts

28 September 2010 at 9:54am

This was really helpful ... I was wondering if you found a way of having the popup maintain the data that was entered on the form when it was invalid?

thanks

Mike

Avatar
Stef87

Community Member, 66 Posts

18 January 2013 at 5:57am

Hi Mike,

Did you ever find a solution to this? I am having trouble finding a way to retain the data and it is causing major headaches.

Thanks

Stef