1

Here's my dropdown list

 <?php

    $dataCategory=ArrayHelper::map(Movies::find()->asArray()->all(),
 'id', 'movie_name');

  echo $form->field($model, 'movie_id')->dropDownList($dataCategory, 
             ['prompt'=>'-Choose a Movie-','onchange'=>'
             $.get( "'.Url::toRoute('screenticketbooking/dependdrop').'", 
             { id: $(this).val() } )
            .done(function( data )
             {
             $( "select#title" ).html( data );
             });
             '])->label(''); 

    ?> 


      <?php 

            $dataPost=ArrayHelper::map(MovieShows::find()->where('movie_id=:
mov_id',['mov_id'=>$model->movie_id])->asArray()->all(), 'id', 'start_date'); 

    echo $form->field($model, 'show_date')
    ->dropDownList($dataPost, 
    ['id'=>'title','prompt'=>'-Select a Date-']
    )->label('');   

    ?>  

My model rules

  public function rules()
        {
            return [
                [['booking_id', 'location_id', 'movie_id', 'theatre_id', 'screen_id', 'show_time_id', 'screen_class_id', 'seat_id', 'show_date', 'is_deleted'], 'required'],
                [['booking_id', 'location_id', 'movie_id', 'theatre_id', 'screen_id', 'show_time_id', 'screen_class_id', 'seat_id', 'created_by', 'updated_by', 'is_deleted'], 'integer'],
                [['show_date', 'created_at', 'updated_at'], 'safe'],
            ];
        }

I have set show_date and movie_id as required in the model but the validation don't work with 'show_date' (even if it is not set it goes to another page on clicking ok)

What should i do to validate the field in the second drop down???

GAMITG
  • 3,810
  • 7
  • 32
  • 51
Bloodhound
  • 2,906
  • 11
  • 37
  • 71

2 Answers2

0

I guess this is the problem:

$( "select#title" ).html( data );

You could change it to:

$( "select#title" ).val( data );

But it depends on what data is. You could have a look here.

Community
  • 1
  • 1
robsch
  • 9,358
  • 9
  • 63
  • 104
0

You try this

$( "#<?php echo Html::getInputId($model, 'show_date');?>" ).html( data );

instead of

$( "select#title" ).html( data );

Below code get dynamic id of HTML element. Also remove your custom id i.e '"id"=>"title"' from second dropdown.

<?php echo Html::getInputId($model, 'show_date');?> 

For example :

<?php echo $form->field($model,'stu_padd_state')->dropDownList($stateList,
        [
            'prompt'=>'---Select State---',
            'onchange'=>'
                $.get( "'.Url::toRoute('dependent/astud_p_city').'", { id: $(this).val() } )
                    .done(function( data ) {
                        $( "#'.Html::getInputId($model, 'stu_padd_city').'" ).html( data );
                    }
                );'    
        ]       
            ); 
    ?>

<?php echo $form->field($model,'stu_padd_city')->dropDownList($cityList, ['prompt'=>'---Select City---']);?>
GAMITG
  • 3,810
  • 7
  • 32
  • 51
  • i tried but when i click on the first dropdown movies are listed that's ok then i selected a movie then on the first dropdown itself the dates are displayed. – Bloodhound Jun 24 '15 at 12:14
  • $( "#'.Html::getInputId($model, 'stu_padd_city').'" ).html( data ); in this use second dropdown attribute id.. – GAMITG Jun 25 '15 at 06:08