使用模态获取选择项的值的方法是什么。如演示示例所示(在模式对话框中使用select2
小部件):
Modal::begin([
'options' => [
'id' => 'kartik-modal',
'tabindex' => false // important for Select2 to work properly
],
'header' => '<h4 style="margin:0; padding:0">Select2 Inside Modal</h4>',
'toggleButton' => ['label' => 'Show Modal', 'class' => 'btn btn-lg btn-primary'],
]);
echo Select2::widget([
'name' => 'state_40',
'data' => $data,
'options' => ['placeholder' => 'Select a state ...'],
'pluginOptions' => [
'allowClear' => true
],
]);
Modal::end();
我得到了要显示和选择的选项,但是我需要将所选值的id保存到某处,这样我就可以将其作为按钮中链接的一部分进行转发。
例如:
Html::button('Example', ['value' => Url::to(['example/example', 'id' => ?]),'class' => 'btn btn-lg btn-primary ']);
答案 0 :(得分:0)
这是一种简单的方法。我做过很多次了。
npm update react
npm install react-dom
使用jquery:
'options' => [
'class'=>'col-md-3','id'=>'id_select',
'placeholder' => 'Select the country',
],
或者如果您更喜欢ajax:
var id_select = $('#id_select').val();
你无法通过php获取所有参数,你需要客户端语言才能得到这个。
但是,我邀请您使用 echo Html::a('<i class="fa fa-check"></i> Send',null,[
'class' => 'btn btn-primary',
'title' => Yii::t('yii', 'Enviar'),
'onclick'=>"
var id_select = $('#id_select').val();
$.ajax({
type:'post',
cache : false,
url : '".Url::toRoute(['example'])."&id='+id_select,
success : function(response) {
//ok
},
error: function() {
alert('Error');
}
});
]);
与模型,更容易和更快。