Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically Change Key Text #524

Closed
hslorenzo opened this issue Feb 13, 2017 · 2 comments
Closed

Dynamically Change Key Text #524

hslorenzo opened this issue Feb 13, 2017 · 2 comments

Comments

@hslorenzo
Copy link

hslorenzo commented Feb 13, 2017

Hi,

Is there a way to change a key (or action key) text dynamically? What I'm trying to do is to change the key text of {next] button to 'Submit' when last input box is in focus.
Here is my js code:

$.keyboard.keyaction.next = function (base) {
      var parent_fieldset = $('#' + base.el.name).parents('fieldset');
      var $prevInput = $('#' + parent_fieldset.attr("id") + ' input:eq(-2)');     
     
     //If 2nd to the last input is in focus
      if ($prevInput.attr("id") == base.el.name) {

              setTimeout(function () {
                  var keyboard = $('.keyboard-normal').keyboard().getkeyboard();
                  keyboard.options.display.next = 'Submit';
                  //keyboard.redraw();
                  $('.ui-keyboard-next').find("span:contains('Go')").text('Submit');
              }, 500);
       }
      

      base.switchInput(true, base.options.autoAccept);
      return false;

  };

It seems to work but when my mouse exited the button the text reverts back to 'Next'.

Thank you in advance.

@Mottie
Copy link
Owner

Mottie commented Feb 13, 2017

Hi @hslorenzo!

I would instead use the visible callback function as follows (demo)

visible: function(e, keyboard, el) {
  if ($(el).hasClass('last')) {
    keyboard.$keyboard.find('.ui-keyboard-next')
      .text('Submit')
      .attr('data-html', '<span class="ui-keyboard-text">Submit</span>');
  }
}

The part you needed was to modify the data-html attribute as it is used when you unhover the key; this is because of the mousewheel option allowing you to scroll through the other keysets.

@hslorenzo
Copy link
Author

hslorenzo commented Feb 13, 2017

Wow! that was quick 👍

I just tried it and it works! You are really awesome. Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants