javascript - How to click on a input field and fire event in knockoutjs and test it? -


What I am trying to achieve is that when the user clicks on the input field, Want to turn on the page? I am using haphocus but this works only for the first time when I click on the search bar and then the event is not called. & lt; Div class = ".home-search-panel" & gt; & Lt; Input type = "search" data-bind = "hasFocus: searchInputFocus ()" name = "q" placeholder = "@. Search placeholder copy" value = "@ request .QueryString [" q "]" maxlength = "150" Class = "input-product-search" autocomplete = "off" /> & Lt; / Div & gt; ) .offset () top. };

And I think this code is using DOM manipulation which is hard to test without using jquery-jasmine .

My thoughts ...

  1. You should searchInputFocus () after ( ), It should only be the search InputFocus
  2. Hasfocus if does not focus on one control, it Creates focus on control If the binding parameter evaluates for the right, therefore, if SearchInputFocus returns right then the knockout input box for the focus will be set in it is a well-explained example that I can not really do better. : -)
  3. It seems that what you really want is an event binding: data-bind = "event: {onfocus: searchInputFocus}" In this case, SearchInputFocus The function is called when the focus on the input box is
  4. According to the suggestion in the comments, click bindings should also work, it can not work for you because after the search inputfox mentioned in point 1 above ( ) May need to be removed. However, if no field will click on the tabs.

    Hope that helps.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -