Skip to content

Commit

Permalink
DEV: add submitButton to widget config
Browse files Browse the repository at this point in the history
  • Loading branch information
TonisOrmisson committed May 24, 2018
1 parent 48f2298 commit 0598c43
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
41 changes: 28 additions & 13 deletions AddressForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,35 @@ class AddressForm extends Widget
/** @var Address */
public $address;


/**
* @var array config yii\bootstrap\ActiveForm
*/
public $formOptions = [];

/** @var string */
public $submitText;

/** @var array $submitOptions the HTML options for submit button */
public $submitOptions = [
'class' => 'btn btn-primary',
];

public function init()
{
parent::init();
$this->registerTranslations();
$this->module = Yii::$app->getModule('addressform');

if (empty($this->address)) {
$this->address = new Address();
} else {
$this->address->validate();
}

if (count($this->allowedCountries) === 1) {
$this->country = country($this->allowedCountries[0]);
}

$this->setDefaults();

$this->placeHolders = [
'name' => Yii::t("addressform", "John Doe"),
'country' => Yii::t("addressform", "Select country"),
'state' => Yii::t("addressform", "Select state"),
'city' => Yii::t("addressform", "New York City"),
'postCode' => Yii::t("addressform", "Post Code"),
'postCode' => Yii::t("addressform", "10001"),
'addressLine1' => Yii::t("addressform", "350 Fifth Avenue"),
'addressLine2' => Yii::t("addressform", "Section, floor, etc."),
'addressLine2' => Yii::t("addressform", "2nd floor, room 203"),
];
}

Expand Down Expand Up @@ -140,5 +137,23 @@ public function getCountries()

}

private function setDefaults()
{
if (empty($this->address)) {
$this->address = new Address();
} else {
$this->address->validate();
}

if (count($this->allowedCountries) === 1) {
$this->country = country($this->allowedCountries[0]);
}

if (empty($this->submitText)) {
$this->submitText = Yii::t("addressform", "Send");
}

}


}
2 changes: 1 addition & 1 deletion views/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
<?= (in_array('postCode', $widget->disabledFields)) ? null: $form->field($model, 'postCode')->textInput(['placeholder'=>$widget->placeHolders['postCode']]) ?>
</div>
</div>
<?= empty($widget->form) ? Html::submitButton() : null?>
<?= empty($widget->form) ? Html::submitButton($widget->submitText,$widget->submitOptions) : null?>

<?php (empty($widget->form)) ? ActiveForm::end() : null?>

0 comments on commit 0598c43

Please sign in to comment.