This commit is contained in:
kali 2024-04-22 11:31:44 +03:00
parent 13dbef5b4f
commit f26754ca79
10 changed files with 61 additions and 39 deletions

View File

@ -15,10 +15,12 @@ function ajaxRequest() {
} }
function getValueSelect(){ function getValueSelect(){
var selectValue = document.getElementById("selectID").value var selectValue = document.getElementById("selectID").value
var inputTags = document.getElementsByTagName('input'); var request = new XMLHttpRequest();
var inputCount = inputTags.length - 3; let button = document.getElementById("buttonAdd");
var request = new XMLHttpRequest() let count = parseInt(button.dataset.count) + 1;
request.open("GET", "/admin/set-value-select?value=" + selectValue + "&count=" + inputCount, true) button.dataset.count = count;
console.log(count);
request.open("GET", "/admin/set-value-select?value=" + selectValue + "&count=" + count, true)
request.addEventListener("load", () => { request.addEventListener("load", () => {
var responseText = request.responseText; var responseText = request.responseText;
var targetElement = document.getElementById("buttonAdd"); var targetElement = document.getElementById("buttonAdd");

View File

@ -4,6 +4,7 @@ namespace itguild\forms;
use itguild\forms\builders\ButtonBuilder; use itguild\forms\builders\ButtonBuilder;
use itguild\forms\builders\CheckBoxBuilder; use itguild\forms\builders\CheckBoxBuilder;
use itguild\forms\builders\HiddenBuilder;
use itguild\forms\builders\RadioButtonBuilder; use itguild\forms\builders\RadioButtonBuilder;
use itguild\forms\builders\SelectBuilder; use itguild\forms\builders\SelectBuilder;
use itguild\forms\builders\TextAreaBuilder; use itguild\forms\builders\TextAreaBuilder;
@ -12,6 +13,7 @@ use itguild\forms\debug\Debug;
use itguild\forms\inputs\BaseInput; use itguild\forms\inputs\BaseInput;
use itguild\forms\inputs\Button; use itguild\forms\inputs\Button;
use itguild\forms\inputs\Checkbox; use itguild\forms\inputs\Checkbox;
use itguild\forms\inputs\Hidden;
use itguild\forms\inputs\RadioButton; use itguild\forms\inputs\RadioButton;
use itguild\forms\inputs\Select; use itguild\forms\inputs\Select;
use itguild\forms\inputs\TextArea; use itguild\forms\inputs\TextArea;
@ -61,6 +63,9 @@ class ActiveForm
elseif ($class === RadioButton::class){ elseif ($class === RadioButton::class){
$this->fieldObject = RadioButtonBuilder::build($name, $params); $this->fieldObject = RadioButtonBuilder::build($name, $params);
} }
elseif ($class === Hidden::class){
$this->fieldObject = HiddenBuilder::build($name, $params);
}
else { else {
$this->fieldObject = new $class($name, $params); $this->fieldObject = new $class($name, $params);
} }

View File

@ -5,6 +5,7 @@ namespace itguild\forms\app\controllers;
use Illuminate\Database\Events\DatabaseBusy; use Illuminate\Database\Events\DatabaseBusy;
use itguild\forms\ActiveForm; use itguild\forms\ActiveForm;
use itguild\forms\app\core\BaseController; use itguild\forms\app\core\BaseController;
use itguild\forms\app\models\FormInputModel;
use itguild\forms\app\models\FormModel; use itguild\forms\app\models\FormModel;
use itguild\forms\core\cg_view\CgView; use itguild\forms\core\cg_view\CgView;
@ -31,12 +32,25 @@ class AdminController extends BaseController
} }
public function saveFormAction(): void public function saveFormAction(): void
{ {
$title = $_POST["title"]; $title = $_POST["title"];
$params = $_POST["params"]; $perPage = $_POST['perPage'];
if (isset($title) and isset($params)) { $inputs = $_POST["InputForm"];
$form = FormModel::Create(['title' => $title, 'status' => FormModel::STATUS_ACTIVE, 'params' => $params]); $inputArray = [];
echo "Форма сохранена!"; foreach ($inputs as $input){
} $form = FormInputModel::Create(['form_id' => 42, 'input_type_id' => $input['type'], 'label' => $input['name'], 'name' => 'adsads', 'params' => "adsasd"]);
Debug::prn($form);
}
$resultArray = ['meta' => ['perpage' => $perPage]];
Debug::prn(json_encode($resultArray, true));
//if (isset($title) and isset($params)) {
// $form = FormModel::Create(['title' => $title, 'status' => FormModel::STATUS_ACTIVE, 'params' => json_encode($resultArray, true)]);
// echo "Форма сохранена!";
//}//
} }
public function getFormAddFieldsAction(): void public function getFormAddFieldsAction(): void
{ {
@ -46,7 +60,6 @@ class AdminController extends BaseController
{ {
$selectValue = $_GET["value"]; $selectValue = $_GET["value"];
$countInput = $_GET["count"]; $countInput = $_GET["count"];
Debug::prn($countInput);
$form = new ActiveForm(); $form = new ActiveForm();
$fields = [ $fields = [
@ -64,9 +77,10 @@ class AdminController extends BaseController
throw new FieldTypeNotFound($selectValue); throw new FieldTypeNotFound($selectValue);
} }
$this->cgView->render("/admin/field_type/$viewName.php", ['form' => new ActiveForm()]); $this->cgView->render("/admin/field_type/$viewName.php", ['form' => new ActiveForm(), 'count' => $countInput]);
} }
} }

View File

@ -9,6 +9,8 @@
use itguild\forms\inputs\Checkbox; use itguild\forms\inputs\Checkbox;
use itguild\forms\inputs\TextInput; use itguild\forms\inputs\TextInput;
$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
'placeholder' => "Наименование"])->setLabel("Наименование (например \"Телефон\")")->render(); $form->field(TextInput::class, name: "InputForm[$count][name]", params: ['class' => "form-control",
$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное")->render(); 'placeholder' => "Наименование поля"])->setLabel("Наименование поля (например \"Телефон\")")->render();
$form->field(Checkbox::class, name: "InputForm[$count][required]", params:['value' => '1'])->setLabel("Обязательное")->render();
$form->field(\itguild\forms\inputs\Hidden::class, name: "InputForm[$count][type]", params: ['value' => '5'])->render();

View File

@ -3,12 +3,14 @@
/** /**
* *
* @var \itguild\forms\ActiveForm $form * @var \itguild\forms\ActiveForm $form
* @var integer $count
* *
*/ */
use itguild\forms\inputs\Checkbox; use itguild\forms\inputs\Checkbox;
use itguild\forms\inputs\TextInput; use itguild\forms\inputs\TextInput;
$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control", $form->field(TextInput::class, name: "InputForm[$count][name]", params: ['class' => "form-control",
'placeholder' => "Наименование"])->setLabel("Наименование (например \"Телефон\")")->render(); 'placeholder' => "Наименование"])->setLabel("Наименование (например \"Телефон\")")->render();
$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное")->render(); $form->field(Checkbox::class, name: "InputForm[$count][required]", params:['value' => '1'])->setLabel("Обязательное")->render();
$form->field(\itguild\forms\inputs\Hidden::class, name: "InputForm[$count][type]", params: ['value' => '1'])->render();

View File

@ -9,6 +9,7 @@
use itguild\forms\inputs\Checkbox; use itguild\forms\inputs\Checkbox;
use itguild\forms\inputs\TextInput; use itguild\forms\inputs\TextInput;
$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control", $form->field(TextInput::class, name: "InputForm[$count][name]", params: ['class' => "form-control",
'placeholder' => "Наименование"])->setLabel("Наименование (например \"Телефон\")")->render(); 'placeholder' => "Наименование"])->setLabel("Наименование (например \"Телефон\")")->render();
$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное")->render(); $form->field(Checkbox::class, name: "InputForm[$count][required]", params:['value' => '1'])->setLabel("Обязательное")->render();
$form->field(\itguild\forms\inputs\Hidden::class, name: "InputForm[$count][type]", params: ['value' => '4'])->render();

View File

@ -10,13 +10,11 @@ use itguild\forms\inputs\Checkbox;
use itguild\forms\inputs\TextArea; use itguild\forms\inputs\TextArea;
use itguild\forms\inputs\TextInput; use itguild\forms\inputs\TextInput;
$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
'placeholder' => "Наименование поля"]) $form->field(TextInput::class, name: "InputForm[$count][name]", params: ['class' => "form-control",
->setLabel("Наименование поля (например \"Телефон\")") 'placeholder' => "Наименование"])->setLabel("Наименование (например \"Телефон\")")->render();
->render(); $form->field(TextArea::class, name: "InputForm[$count][options]", params: ['class' => "form-control"])
$form->field(TextArea::class, name: "OptionsInput", params: ['class' => "form-control"])
->setLabel("Опции выпадающего списка") ->setLabel("Опции выпадающего списка")
->render(); ->render();
$form->field(Checkbox::class, name: "RequiredInput", params:[]) $form->field(Checkbox::class, name: "InputForm[$count][required]", params:['value' => '1'])->setLabel("Обязательное")->render();
->setLabel("Обязательное поле") $form->field(\itguild\forms\inputs\Hidden::class, name: "InputForm[$count][type]", params: ['value' => '6'])->render();
->render();

View File

@ -3,14 +3,16 @@
/** /**
* *
* @var \itguild\forms\ActiveForm $form * @var \itguild\forms\ActiveForm $form
* @var integer $count
* *
*/ */
use itguild\forms\inputs\Checkbox; use itguild\forms\inputs\Checkbox;
use itguild\forms\inputs\TextInput; use itguild\forms\inputs\TextInput;
$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control", $form->field(TextInput::class, name: "InputForm[$count][name]", params: ['class' => "form-control",
'placeholder' => "Наименование поля"])->setLabel("Наименование поля (например \"Телефон\")")->render(); 'placeholder' => "Наименование поля"])->setLabel("Наименование поля (например \"Телефон\")")->render();
$form->field(TextInput::class, name: "PlaceholderInput", params: ['class' => "form-control", $form->field(TextInput::class, name: "InputForm[$count][placeholder]", params: ['class' => "form-control",
'placeholder' => 'Placeholder'])->setLabel("Placeholder")->render(); 'placeholder' => 'Placeholder'])->setLabel("Placeholder")->render();
$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное поле")->render(); $form->field(Checkbox::class, name: "InputForm[$count][required]", params:['value' => '1'])->setLabel("Обязательное")->render();
$form->field(\itguild\forms\inputs\Hidden::class, name: "InputForm[$count][type]", params: ['value' => '2'])->render();

View File

@ -9,8 +9,9 @@
use itguild\forms\inputs\Checkbox; use itguild\forms\inputs\Checkbox;
use itguild\forms\inputs\TextInput; use itguild\forms\inputs\TextInput;
$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control", $form->field(TextInput::class, name: "InputForm[$count][name]", params: ['class' => "form-control",
'placeholder' => "Наименование поля"])->setLabel("Наименование поля (например \"Телефон\")")->render(); 'placeholder' => "Наименование поля"])->setLabel("Наименование поля (например \"Телефон\")")->render();
$form->field(TextInput::class, name: "PlaceholderInput", params: ['class' => "form-control", $form->field(TextInput::class, name: "InputForm[$count][placeholder]", params: ['class' => "form-control",
'placeholder' => 'Placeholder'])->setLabel("Placeholder")->render(); 'placeholder' => 'Placeholder'])->setLabel("Placeholder")->render();
$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное поле")->render(); $form->field(Checkbox::class, name: "InputForm[$count][required]", params:['value' => '1'])->setLabel("Обязательное")->render();
$form->field(\itguild\forms\inputs\Hidden::class, name: "InputForm[$count][type]", params: ['value' => '3'])->render();

View File

@ -24,12 +24,7 @@ $form->field(TextInput::class, name: "perPage", params: [
]) ])
->setLabel("Количество выводимых записей на страницу") ->setLabel("Количество выводимых записей на страницу")
->render(); ->render();
$form->field(TextArea::class, name: "paramsForm", params: [
'class' => "form-control",
'placeholder' => 'Параметры'
])
->setLabel("Параметры")
->render();
$form->field(\itguild\forms\inputs\Select::class, name: "inputType", params: [ $form->field(\itguild\forms\inputs\Select::class, name: "inputType", params: [
'class' => "form-control-sm", 'class' => "form-control-sm",
'id' => "selectID", 'id' => "selectID",
@ -39,7 +34,7 @@ $form->field(\itguild\forms\inputs\Select::class, name: "inputType", params: [
->setLabel("Добавить поле") ->setLabel("Добавить поле")
->render(); ->render();
?> ?>
<button style="margin-top:15px" type="button" id="buttonAdd" class="btn btn-success " onclick="getValueSelect()">Добавить поле</button> <button style="margin-top:15px" type="button" id="buttonAdd" class="btn btn-success " onclick="getValueSelect()" data-count=0>Добавить поле</button>