JutoApp / meteor-autoform-telephone-input

Meteor Autoform plugin for entering and validating international telephone numbers
2 stars 0 forks source link

How to pass options to the input #1

Closed nasuke0302 closed 5 years ago

nasuke0302 commented 5 years ago

Hi, I have a doubt, is it possible and if so how to pass (intl-tel-input) options to the input from the schema. I mean I would like to have a different initialCountry in the rendered input. Thanks, nice package btw.

Edit: I tried this: autoform: { afFieldInput: { type: "intl-tel", autocomplete: "tel", initialCountry: 'mx' } },

cunneen commented 5 years ago

Hi @nasuke0302 , you can access and manipulate the input element within your templates' onRendered callback.

//called once when an instance of Template.myTemplate is rendered into DOM nodes and put into the document for the first time
Template.myTemplate.onRendered(function () {
  // This can be a good place to apply any DOM manipulations you want, after the template is rendered for the first time.
  // use 'this' to access the template instance.
  let itiElemJQ = this.$(".intl-tel-input input");
  if (itiElemJQ.val() === "") { // set the initial country if there's no value already
    let itiElement = itiElemJQ[0];
    let iti = window.intlTelInputGlobals.getInstance(itiElement);
    iti.setCountry("JP");
  }
});

Currently there are no options that are passed via the schema. Feel free to submit a pull request.

nasuke0302 commented 5 years ago

Thanks for the quick answer