Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Не срабатывает функция


VladRom
 Share

Recommended Posts

Здравствуйте, я не понимаю почему не срабатывает тригер кнопки

$('#search input[name=\'search\']').parent().find('button').trigger('click')

Вот код common-js

    $('#search input[name=\'search\']').parent().find('button').on('click', function() {
        var url = $('base').attr('href'+ 'index.php?route=product/search';
 
        var value = $('header #search input[name=\'search\']').val();
 
        if (value) {
            url += '&search=' + encodeURIComponent(value);
        }
 
        location = url;
    });
 
    
 
    $('#search input[name=\'search\']').on('keydown', function(e) {
        console.log(e.keyCode);
        
        if (e.keyCode == 13) {
            
            $('#search input[name=\'search\']').parent().find('button').trigger('click')
        }
    });

Вот search.twig

<div class="" id="search" >
<button type="button" class="search-form__icon"><i class="fa fa-search"></i></button>
    <form action="#" class="search-form__item">
      <button  type="button" class="btn btn-default btn-lg search-form__btn _icon-search" id = "main-search-button"></button>
      <input type="text" name="search" value="{{ search }}" placeholder="{{ text_search }}" class="form-control input-lg search-form__input" />
    </form>
</div>

 

 

 

 

Edited by VladRom
Link to comment
Share on other sites


А зачем вам две кнопки в форме поиска?
Вместо этот "конструкции":

$('#search input[name=\'search\']').parent().find('button')

везгде пропишите

$('#main-search-button')

или ик

$('#search form button')

P.S. Только уберите пробелы в этот части шаблона:

id = "main-search-button"

 

Link to comment
Share on other sites


4 часа назад, ocbot сказал:

А зачем вам две кнопки в форме поиска?
Вместо этот "конструкции":

$('#search input[name=\'search\']').parent().find('button')

везгде пропишите

$('#main-search-button')

или ик

$('#search form button')

P.S. Только уберите пробелы в этот части шаблона:

id = "main-search-button"

 

Вторая кнопка для мобильной версии.

Я уже изменял у меня все равно она не тригерится, но с гдефолтным кодом она тригерится

<div id="search" class="input-group">
  <input type="text" name="search" value="{{ search }}" placeholder="{{ text_search }}" class="form-control input-lg" />
  <span class="input-group-btn">
    <button type="button" class="btn btn-default btn-lg"><i class="fa fa-search"></i></button>
  </span>
</div>

 

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.