active-form

Yii2 updating two related models does not show data of the second

妖精的绣舞 提交于 2020-01-06 19:55:34
问题 I have two related models in hasToMany relation. The first is Invoices and the second is InvoiceItems . As a prototype process, I'm trying to conjugate the two models through the update view of the InvoicesController using the following code in actionUpdate of InvoicesController : ... use common\models\Invoices; use common\models\InvoicesSearch; use common\models\InvoiceItems; ... public function actionUpdate($id) { $model = $this->findModel($id); $invoiceItems = new InvoiceItems(); if (

Radio Button group in separate place in yii2

一曲冷凌霜 提交于 2020-01-02 04:09:06
问题 So, I want to have two radio button in separate place, I have been trying to search for the solution and everyone suggests to use radiolist which is not possible in my case. If I put it like this (work_part_time button) : (below) <div class="row"> <div class="col-sm-2"> <?= $form->field($model, 'work_part_time')->radio(['label' => 'yes', 'value' => 1])?> </div>- <div class="col-sm-3"> <?= $form->field($model, 'hour_week')->textInput(['type' => 'number', 'placeholder' => 'Hour/Week'])->label

Radio Button group in separate place in yii2

不羁岁月 提交于 2020-01-02 04:09:04
问题 So, I want to have two radio button in separate place, I have been trying to search for the solution and everyone suggests to use radiolist which is not possible in my case. If I put it like this (work_part_time button) : (below) <div class="row"> <div class="col-sm-2"> <?= $form->field($model, 'work_part_time')->radio(['label' => 'yes', 'value' => 1])?> </div>- <div class="col-sm-3"> <?= $form->field($model, 'hour_week')->textInput(['type' => 'number', 'placeholder' => 'Hour/Week'])->label

rails link_to tag to build join record in rails

核能气质少年 提交于 2019-12-25 04:19:46
问题 I'm trying to build a form that allows a user to add products to an order. The way I have it setup so far is that a user will select from 2 dropdown boxes and type into 1 text field 1 - the product they want 2 - its size 3 - the quantity they want. What I hope to do is have the user click a link_to tag to "Add" this item to their order. I was thinking I could do this via ajax and build the associative record in my controller and have it render on the page when the request returns. When the

yii2: make checkbox to be checked

好久不见. 提交于 2019-12-22 04:36:19
问题 I am using Yii2 framework and I'd like to generate an html code like this <input type="checkbox" id="queue-order" name="Queue[order]" value="1" checked> in a view which uses ActiveForm. I've tried echo $form->field($model, 'order') ->checkBox(['label' => ..., 'uncheck' => null, 'checked' => true]); as well as echo $form->field($model, 'order') ->checkBox(['label' => ..., 'uncheck' => null, 'checked' => 'checked']); but desired string "checked" does not appear in the generated html code.

Yii2 activeform ajax submit and validation

自古美人都是妖i 提交于 2019-12-20 10:39:34
问题 Currently to achieve ajax submit and validation at the same time. I'm using custom function like: $('.edit_form').submit(function (e) { e.preventDefault(); var form = $(this); var formData = $(this).serialize(); if (form.find('.has-error').length) { return false; } $.ajax({ url: form.attr("action"), type: form.attr("method"), data: formData, success: function (data) { ... }, error: function () { alert("Something went wrong"); } }); }); And here is php side, for validation my config looks like

How to set Yii2's ActiveForm checkbox in checked state?

好久不见. 提交于 2019-12-19 19:52:21
问题 I'm looking for a simple solution for a "checked" state for the Yii2 ActiveForm checkbox control and I can't find a solution how to set it. I cant find any examples in the documentation. I've tried to manipulate the rendering code <?= $form->field($model, 'name')->checkbox()->label('Hi'); ?> But it seems I need to modify the ActiveForm itself. How to make checkbox checked by default? 回答1: Ok, I've debbuged a while and found a solution, it lies in the guts of BaseHtml.php at line 1359 in

js active form validation in yii2

六眼飞鱼酱① 提交于 2019-12-14 03:29:46
问题 I have a active form and I am trying to validate it using the script written below : jQuery("#form").yiiActiveForm("submitForm"); The problem is, the script always returns false. But when I call it second time with some delay, it returns true. jQuery("#form").yiiActiveForm("submitForm"); setTimeout(function () { if (jQuery("#form").yiiActiveForm("submitForm")) { //ajax call... } }, 300); My question is, how does validation works in yii2 ? And is there a better way to validate active forms in

Yii2 ActiveForm validation error on Kartik's FileInput widget

不问归期 提交于 2019-12-13 03:49:15
问题 I have an ActiveForm with Kartik's FileInput widget. It is a type of Edit Form. I am fetching db data in it along with images. Case 1 - If Image is already added, it is showing large-image field as required whenever I click on update button. Case 2 - If I Choose new image, it is working fine. How can I set some value for FileInput for existing images to make it not empty/valid. I want some solution for case1. Each time its asking for new image to update any changes. Please help me to fix this

How to update widget with pjax in modal window in yii2

眉间皱痕 提交于 2019-12-12 07:20:12
问题 I have two ActiveForms in a modal window and after submitting first form, I need to update second one and stay in modal. As I understand pjax can handle that, but can't get it to work properly. In _form.php I have ActiveForm with widget wich should be updated: <?php $form = ActiveForm::begin([ 'id'=>'form', 'enableAjaxValidation'=>true, ]); ?> <?= Html::activeHiddenInput($riskModel, 'id', ['value' => $riskModel->id]) ?> <?php Pjax::begin([ 'id' => 'solutionItems', ]) ?> //need to update this