Hi Ramarao,

what you want is currently not possible in plain tobago. You need additional
javascript to archive this.



Try the following code:

<tc:cell>
   <tc:script onload="initInput('page:search')">
      initInput = function(id) {
        var input = Tobago.element(id);
        Tobago.addEventListener(input, "keyup", "submitActionOnEnter(event)");
      }
      submitActionOnEnter = function(event) {
        if (!event) { event = window.event;}

        var keyCode;
        if (event.which) {
          keyCode = event.which;
        } else {
          keyCode = event.keyCode;
        }

        if (keyCode == 13) {
          var input = Tobago.element(event);
          if (input) {
            if (input.value.length > 0) {
              var linkId = input.id.substr(0,
input.id.lastIndexOf(":") + ":searchLink");
              Tobago.submitAction(linkId);
            } else {
              alert("No value in search field!")
            }
          }
        }
      }
      checkAndSubmit = function(event) {
        if (!event) { event = window.event;}
        var link = Tobago.element(event);
        var inputId = link.id.substr(0, link.id.lastIndexOf(":") + ":search");
        var input = Tobago.element(inputId);
        if (input) {
          if (input.value.length > 0) {
            Tobago.submitAction(link.id);
          } else {
            alert("No value in search field!")
          }
        } else {
          alert("input not found");
        }
      }
   </tc:script>
   <tc:in id="search" width="130px"
       value="#{search.searchText}"
       suggestMethod = "#{search.suggestSearch}" />
   <tc:link image="img/search.gif"
            id="searchLink"
            onclick="checkAndSubmit(event)"
            action="#{search.searchItems}" />
</tc:cell>

note: I have not tested nor compiled this so there may be errors in
the javascript, but you should get how to do this.


Regards,
   Volker



2007/7/20, Ramarao Venkata <[EMAIL PROTECTED]>:
Hi,

I has a tc:in and a tc:link.  when we click on the link the form is submited
even though no value value in tc:in.
When there is no value in tc:in and pressed on <tc:link i should not submit
instead i should display an alert message.

With in tc:in when i press enter i need to invoke the action specified in
tc:link. do i need register for any key listener

My code is written as below

<tc:cell>
     <tc:in id="search" width="130px"
         value="#{search.searchText}"
         suggestMethod = "#{search.suggestSearch}" />
     <tc:link image="img/search.gif"
              action="#{search.searchItems}" />
 </tc:cell>


kindly suggest a solution.

regards
Ramarao











Reply via email to