function testPublishingMultipleOptions() { $id = $this->form->ID; $this->form->Fields()->removeAll(); // test a editable option field $dropdown = new EditableDropdown(); $dropdown->write(); $checkbox = new EditableCheckboxGroupField(); $checkbox->write(); $option = new EditableOption(); $option->write(); $option2 = new EditableOption(); $option2->write(); $dropdown->Options()->add($option); $checkbox->Options()->add($option2); $this->form->Fields()->add($dropdown); $this->form->Fields()->add($checkbox); // upon adding it, it shouldn't be on the live site $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = {$id}"); $this->assertFalse($live); // and when published it should exist and the option $this->form->doPublish(); $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = {$id}"); $this->assertEquals($live->Fields()->Count(), 2); // check they have options attached foreach ($live->Fields() as $field) { $this->assertEquals($field->Options()->Count(), 1); } }
/** * Return the html for a field option such as a * dropdown field or a radio check box field * * @return bool|html */ public function addoptionfield() { // passed via the ajax $parent = isset($_REQUEST['Parent']) ? $_REQUEST['Parent'] : false; // work out the sort by getting the sort of the last field in the form +1 if ($parent) { $sql_parent = Convert::raw2sql($parent); $highestSort = DB::query("SELECT MAX(\"Sort\") FROM \"EditableOption\" WHERE \"ParentID\" = '{$sql_parent}'"); $sort = $highestSort->value() + 1; if ($parent) { $object = new EditableOption(); $object->write(); $object->ParentID = $parent; $object->Sort = $sort; $object->Name = 'option' . $object->ID; $object->write(); return $object->EditSegment(); } } return false; }
/** * Return the html for a field option such as a * dropdown field or a radio check box field * * @return bool|html */ public function addoptionfield() { if (!SecurityToken::inst()->checkRequest($this->request)) { return $this->httpError(400); } // passed via the ajax $parent = isset($_REQUEST['Parent']) ? $_REQUEST['Parent'] : false; // work out the sort by getting the sort of the last field in the form +1 if ($parent) { $sql_parent = (int) $parent; $sqlQuery = new SQLQuery(); $sqlQuery = $sqlQuery->setSelect("MAX(\"Sort\")")->setFrom("\"EditableOption\"")->setWhere("\"ParentID\" = {$sql_parent}"); $sort = $sqlQuery->execute()->value() + 1; if ($parent) { $object = new EditableOption(); $object->write(); $object->ParentID = $parent; $object->Sort = $sort; $object->Name = 'option' . $object->ID; $object->write(); return $object->EditSegment(); } } return false; }