Custom Category Field in Yii

54 views Asked by At

I'm modifying a classified application made in the Yii framework. The application already includes category-based fields, Now I want to trigger another input field with the same code. I tried adding the $('.price-type').show(); in JS. But it didn't help.

JS File

    $(document).on('click','#modal-category .modal-footer #success-selection',function (e) {
    e.preventDefault();
    $('#choose-class').text($(this).data('selectedText'));
    $('input#listing-category_id').val($(this).data('selectedId'));

    $.post($('#category-fields').data('url'),{
        category_id:$(this).data('selectedId'),
        listing_id:$('#post-form').data('listing'),
    },function (json) {
        if(json.html) {
            $('.category-fields').show();
            $('.price-types').show();
            $('#category-fields').html(json.html);
            $('select').select2({
                width: '100%',
                language: site.language,
                dir: site.dir,
            });
        }else{
            $('.category-fields').hide();
        }
    }, 'json');
});

Form.php

<div class="row price-types" id="price-types" style="display: none">
    <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
        <?= $form->field($ad, 'pricetype', [
            'template'      => '{input} {error}',
        ])->textInput(['placeholder' => t('app', 'Price Type'), 'class' => 'form-control'])->label(false); ?>
    </div>
</div>

<div class="row category-fields" id="category-fields" data-url="<?= url(['/listing/get-category-fields']); ?>" style="display: none">
</div>
1

There are 1 answers

0
Ramisha Mukhtar On

Please try using

$(document). ready(function() {
$('.price-types').hide();
});

instead of using style="display: none" for the div and then you can unhide the element as :

$('.price-types').show();

on any desired event.