Jump to content

Populating field defaults... can only update value, not input?


hellomoto
 Share

Recommended Posts


	public function init() {

		// add a hook after each page is saved
		$this->pages->addHookAfter('saved', $this, 'populateDefaults');

	}

	/**
	 * Populates model defaults after save for corresponding blank fields.
	 *
	 */
	public function populateDefaults($event) {

		$page = $event->arguments('page'); 
		if($page->template != 'vessel') return;

		//$this->message("hi {$page->model->hulls}");

		if($page->model && !$page->hulls && $page->model->hulls) {
			$page->set("hulls", $page->model->hulls);
			$this->message("hi $page->hulls {$page->model->hulls}");
		}

	}

This sort of works; the message echoed is "hi 1082 1082". When I set the hulls to null in the above code, it then goes back to "hi 1082". However, it doesn't update the select input in the edit screen, and the "Missing required value" error for that field remains... Also the message shouldn't even be showing if $page->hulls is set... How can I get it to update the field value and the input?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...