PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 3, 2022

[FIXED] Yii array helper selecting already set value from database

 March 03, 2022     array-map, javascript, php, yii, yii2     No comments   

Issue

Am using array helpers if data exists i want to select the value...here product category master id is a foreign key in product master table. A modal gets called on edit button and it uses the same modal as create button but the fields are populated using hidden input field.

I want to select the already set value from the database.

                       $("#productmaster-product_category_master_id").val(data.product_category_master_id);

The above code is not working.

<?= $product_form->field($form_product_model, 'product_category_master_id')->dropDownList(

                                ArrayHelper::map(ProductCategoryMaster::find()->all(),'id','category'),['prompt'=>'','class'=>'form-control select2','style' => 'width:100%;height:80% !important']

                            );?>



function editProduct(id) {
    console.log(id);
    $.ajax
    ({
        type:"GET",
        url: "<?= Yii::getAlias('@web')?>/product-category-master/product?id="+id,
        cache: false,
        dataType:"json",
        success: function(data)
        {
            console.log(data);

            $('#sourceproduct').click();
                       $("#newid").val(data.id);

                       $("#productmaster-product_category_master_id").val(data.product_category_master_id);
                                    //document.getElementById("editbutton").showModal();
                        //var myArr = JSON.parse(data);

            return false;
        }
    });


}

Solution

Found the solution i just had to put

$('#productmaster-product_category_master_id').val(data.product_category_master_id).trigger('change'); 

instead of

$('#productmaster-product_category_master_id').val(data.product_category_master_id);


Answered By - Sourabh Shah
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing