Unable to initialize external jQuery in Magento2

I would like to initialize intlTelInput for the country code column. I have done below,

in requirejs.config.js added below

var config = {     deps: [     "Ucs_Reson8/js/countryCode"   ],   paths: {     'intlTelInput': 'Ucs_Reson8/js/intlTelInput',   },   shim: {     'intlTelInput': {       deps: ['jquery'],       exports: 'jQuery.fn.intlTelInput',     }   }  }; 

Then in countryCode.js added below,

require([ 'jquery', 'intlTelInput', ], function($  ) {         console.log('sample function 1234567');         $  (window).load(function() {             jQuery("#country_code").intlTelInput({                 initialCountry: "ae",                 separateDialCode: true,                 preferredCountries: ["ae","bh","kw","om","qa","sa"],                 //onlyCountries: ["ae","bh","kw","om","qa","sa"],              });     });     }); 

But I am getting the error as below in the browser console.

TypeError: jQuery(…).intlTelInput is not a function

But in the page source I can see the utilsIntel.js

Facing difficulty in initialize i18next react component with fetch response data?

I am using i18next to do the internalization.

Default fetch request used to get a data from server and the language information available in response data. Based on language info the page has to be loaded with corresponding language

import i18n from 'i18next'; import { reactI18nextModule } from 'react-i18next'; import LanguageDetector from 'i18next-browser-languagedetector'; import translationEN from './locales/en/translation.json'; import translationDE from './locales/de/translation.json';  // the translations let language; function sendRequest(resources) {   console.log('resources', resources);   i18n     .use(reactI18nextModule) // passes i18n down to react-i18next     .init(       {         resources,         lng: language,         fallbackLng: 'en',         keySeparator: false, // we do not use keys in form messages.welcome          interpolation: {           escapeValue: false // react already safes from xss         }       },       function() {         fetch('http://localhost:3100/getLang')           .then(data => data.json())           .then(res => {             console.log(res);             language = res.lang;             i18n.changeLanguage(language, (err, t) => {               if (err)                 return console.log(                   'something went wrong loading the language',                   err                 );             });           });       }     );   return i18n; } function i18() {   const resources = {     en: {       translation: translationEN     },     de: {       translation: translationDE     }   };   return sendRequest(resources); } export default i18(); 

Language variable is undefined initially. For the very first time i18n init method setup with “fallbackLng” variable instead of “lng”. After that fetch request goes in callback of init method. That will have the response of language need to used. Then i18n changeLanguage method will help to change language.

I am just wondering how can i execute fetch request prior to i18n initialization. I don’t like the approach of initialize the i18next with some default language first and then moved to different language. When i tried to initialize i18n in then part of fetch request doesn’t works for me.

Is there any alternative way available to execute fetch request first and then setup i18n before exporting the component?

Thanks in advance for any suggestion!

Var app. ¿Es necesario colocar mi código dentro de var app ={ initialize: function() { }, … }

Alguien puede explicar como funciona y si es necesario usar ese modelo para mi app. Tengo unas 1500 (mil quinientas) lineas de código y tengo todo el código suelto dentro de mi index.js eso es una mala practica o podría traerme errores. Por otra parte como uso jquery no estoy usando document.addEventListener('deviceready', this.onDeviceReady, false); sino que uso $ .on Gracias por responder

ES6 – Where is it better to initialize a member – parent class or derived class?

I am trying to figure out if there is a better practice for initializing class members of derived classes in ES6 – in the child or the parent, and why?

For example:

Option 1:

class AbstractAnimal {    constructor() {        this.voice = null;    }     makeVoice() {       this.voice.make();     } }  class Dog extends AbstractAnimal {    constructor() {        super();        this.voice = new Bark();    }     onSeeFriend() {        this.makeVoice();    } } 

Option 2:

class AbstractAnimal {    constructor(voice) {        this.voice = voice;    }     makeVoice() {       this.voice.make();     } }  class Dog extends AbstractAnimal {    constructor() {        super(new Bark());    }     onSeeFriend() {        this.makeVoice();    } } 

Obviously, there are pro’s and cons in both methods. The first options spreads the initialization of members around, which makes it harder to trace. While the second option will bubble everything up to one place, but than you could end up with huge constructors taking a lot of arguments.

Would appreciate it if I could hear your thought about this. Thanks!

Payment Gateway needs Initialize and Authorize

I am developing Saferpay payment gateway for Commerce 2.x Drupal 8. It should be off-site (iFrame) payment.

So in short. In order to complete transaction, first I have to call “/Payment/v1/PaymentPage/Initialize” which returns me a link for an Iframe and that actually works.

$  payload = array(   'RequestHeader' => array(     'SpecVersion' => "1.10",     'CustomerId' => "custID",     'RequestId' => "reqID",     'RetryIndicator' => 0   ),   'TerminalId' => "TermID",   'PaymentMethods' => array("VISA", "MASTERCARD"),   'Payment' => array(     'Amount' => array(       'Value' => "1234",       'CurrencyCode' => "EUR"     ),     'OrderId' => "123",     'Description' => "desc_123"   ),   'ReturnUrls' => array(     'Success' => $  form['#return_url'],     'Fail' => $  form['#cancel_url']   ),   'Styling' => array(     'Theme' => "NONE"   ) ); 

Then i build an iFrame

$  response = RedirectCheckout::do_curl($  username, $  password, $  url_init, $  payload); $  redirectURL = $  response['body']['RedirectUrl']; $  form = $  this->buildRedirectForm($  form, $  form_state, $  redirectURL, $  response, "POST"); return $  form; 


public function buildRedirectForm(array $  form, FormStateInterface $  form_state, $  redirect_url, array $  data, $  redirect_method = BasePaymentOffsiteForm::REDIRECT_POST){ $  form['saferpay_markup'] = [   '#type' => 'inline_template',   '#template' => '<iframe src="' . $  redirect_url . '"></iframe>', ]; return $  form;} 

Second, I have to use “/Payment/v1/Transaction/Authorize” to autohrize the transaction.

My problem is that “onReturn” function always finishes the Order before its actually finished, before I run it through Autohrize.

My Questions:

  1. How can I read data that has been sent from off-site payment form (redirect method = POST)
  2. Whats the best way to implement Authorize in between.

Sorry for the long post guys, I wanted to explain as best as I can.

Thanks for your response.

Force field initialize not by constructor in c++

My parent class has a vector field

I want to force child classes to push in that vector as many as items they have.
At least one item


class Options {     protected:         vector<string> optionItems;     public:         void printItemsInConsole(){             // prints items on console         } }  class MainOptions : public Options {     //have to pushback {Open game, Open highScores, Exit} options for example  }  class SideOptions : public Options {     // have to pushback {Clear game database, Uninstall game, Back to main menu} options for example } 

How to force child classes to push back their items?

I don’t want to pass items in constructor and then put them in vector just right there, because some times items would be a lot, so it isn’t a clean way then

sudo command sudo: /etc/sudoers is world writable sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin

I have run this command by mistake chmode -R 777 ./*.Now not able to use sudo and can’t open folders as root. sudo: /etc/sudoers is world writable sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin