Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?=
- $form->field($model, 'address')->widget(Select2::className(), [
- 'options' => ['placeholder' => 'Inserta an address '],
- 'pluginOptions' => [
- 'allowClear' => true,
- 'minimumInputLength' => 3,
- 'ajax' => [
- 'url' => Url::to(['register/addresses']),
- 'dataType' => 'json',
- 'data' => new JsExpression('function(params) { return {q:params.term}; }')
- ],
- 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
- 'templateResult' => new JsExpression('function(address) { return address.name; }'),
- 'templateSelection' => new JsExpression('function (address) { return address.name; }'),
- ],
- 'pluginEvents' => [
- "select2:select" => "function(e) {
- // some function
- }",
- ],
- ]);
- ?>
- 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
- 'templateResult' => new JsExpression('function(address) { return address.name; }'),
- 'templateSelection' => new JsExpression('function (address) { return address.name; }'),
- public function actionAddresses($q = NULL, $id = NULL)
- {
- Yii::$app->response->format = Response::FORMAT_JSON;
- $results = array();
- if (!is_null($q)) {
- $geocoder = new GeocodingClient();
- $request = $geocoder->lookup(['address' => $q]);
- $counter = 1;
- foreach ($request['results'] as $key => $value) {
- $results['results'][] = [
- 'id' => $counter,
- 'text' => $value['formatted_address'], // Instead of 'name'
- 'coordinate' => $value['geometry']['location']
- ];
- $counter++;
- }
- }
- return $results;
- }
- <?=
- $form->field($model, 'address')->widget(Select2::className(), [
- 'initValueText' => $model->address,
- 'value' => $model->address,
- 'options' => ['placeholder' => 'Inserta an address '],
- 'pluginOptions' => [
- 'allowClear' => true,
- 'minimumInputLength' => 3,
- 'ajax' => [
- 'url' => Url::to(['register/addresses']),
- 'dataType' => 'json',
- 'data' => new JsExpression('function(params) { return {q:params.term}; }')
- ],
- 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
- 'templateResult' => new JsExpression('function(address) { return address.name; }'),
- 'templateSelection' => new JsExpression('function (address) { return address.name; }'),
- ],
- 'pluginEvents' => [
- "select2:select" => "function(e) {
- // some function
- }",
- ],
- ]);
- ?>
- <?php
- $product = $model->product_id ? Product::findOne($model->product_id)->name : 'select ....';
- echo $form->field($model, 'product_id')->widget(Select2::classname(), [
- 'initValueText' => $product, // set the initial display text
- // 'options' => ['placeholder' => 'select ....'],
- 'pluginOptions' => [
- 'allowClear' => true,
- 'minimumInputLength' => 3,
- 'ajax' => [
- 'url' => Url::to(['list']),
- 'dataType' => 'json',
- 'data' => new JsExpression('function(params) { return {q:params.term}; }')
- ],
- 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
- 'templateResult' => new JsExpression('function(product_id) { return product_id.name; }'),
- 'templateSelection' => new JsExpression('function (product_id) { return product_id.name; }'),
- ],
- ]);?>
- $model->id = 1; // or if arrays [1,3,4,5]
- $username = User::find()->select('name')->where('id' => $model->id)->scalar();
- $form->field($model, 'username')->widget(Select2::className(), [
- 'initValueText' => $username;
- ...
Add Comment
Please, Sign In to add comment