I used extension intl-phone-input and noticed that it doesn’t allow to have more than one input on page, because of repeating same id. So i changed code of function run() and registerClientScript() to that:
/**
* Executes the widget.
* This method registers all needed client scripts and renders
* the text field.
*/
public function run()
{
list($name, $id)=$this->resolveNameID();
if(!isset($this->htmlOptions['id']))
$this->htmlOptions['id']=$id;
if(!isset($this->htmlOptions['name']))
$this->htmlOptions['name']=$name;
$this->registerClientScript();
if($this->hasModel()) {
$value=$this->model->{$this->attribute};
echo CHtml::activeHiddenField($this->model, $this->attribute);
}
else {
$value=$this->value;
echo CHtml::hiddenField($this->htmlOptions['name'], $this->value);
}
$htmlOptions=$this->htmlOptions;
unset($htmlOptions['name']);
$htmlOptions['id'] = 'yt' . $htmlOptions['id'];
echo CHtml::textField('intl-phone-input', $value, $htmlOptions);
}
/**
* Registers the needed CSS and JavaScript.
*/
private function registerClientScript()
{
$id = $this->htmlOptions['id'];
$assets=Yii::app()->getAssetManager()->publish(dirname(__FILE__) . '/build');
$lib=Yii::app()->getAssetManager()->publish(dirname(__FILE__) . '/lib');
$this->utilsScript=$lib . '/libphonenumber/build/utils.js';
// Configures JavaScript
$config=$this->config();
$options=CJavaScript::encode($config);
$js="jQuery('#yt$id').intlTelInput({$options});";
$clone='val()';
if($this->E164 === true)
$clone='intlTelInput(\'getNumber\')';
$js.="jQuery('#yt$id').change(function() {
jQuery('#$id').val(jQuery(this).{$clone});
});";
if($this->localisedCountryNames === true) {
$js.="var countryData = $.fn.intlTelInput.getCountryData();
$.each(countryData, function(i, country) {
country.name = country.name.replace(/.+\((.+)\)/,'$1');
});";
}
$cs=Yii::app()->getClientScript();
$cs->registerCssFile($assets . '/css/intlTelInput.css');
$cs->registerScriptFile($assets . '/js/intlTelInput.min.js');
$cs->registerScript(__CLASS__ . '#' . $id, $js);
}
And it works fine.
Don’t have permission to comment on extension page, maybe someone else can do it.