Hi,
I would like to ask if there is a component that looks and behavies like a typical phone input component? More precise, I'm looking for a textbox, that has a dropdown included with all the various countries and its dialling codes. In addition, the dropdown should change its value based on the entered phone number, for example, if someone enters +1, the "country"-dropdown should automatically change to "US +1". Of course, beside the "visual" appearance of the component, the component should also perform some validations and some typical UX-features, like changing the dropdown-value when entering a international number in the text field, ...
Below some example images of typical phone input fields:
(image taken from https://github.com/jackocnr/intl-tel-input)

(image taken from https://gitlab.com/catamphetamine/react-phone-number-input)
I suppose there is no specific component for this. However, are there any existing implementations of such an input field (combination of textbox and dropdown)?
Thanks.
|
function App() {
var data = [
{ Eimg: 'us', CountryCode: '+1', Country: 'United States' },
{ Eimg: 'gb', CountryCode: '+44', Country: 'United Kingdom' },
{ Eimg: 'af', CountryCode: '+93', Country: 'Afghanistan' },
{ Eimg: 'al', CountryCode: '+355', Country: 'Albania' },
{ Eimg: 'dz', CountryCode: '+213', Country: 'Algeria' },
];
var fields = { text: 'Country', value: 'Eimg' };
function itemTemplate(data) {
return (
<div>
<img className="empImage" src={"https://flagcdn.com/16x12/" + data.Eimg +".png"} height="11px" width="20px" alt="employee" />
<div className="ename"> {data.Country} </div>
<div className="job"> {data.CountryCode} </div>
</div>
);
}
var src = "./public/images/af.png";
function valueTemplate(data) {
return (
<div>
<img className="valueTemp" src={"https://flagcdn.com/16x12/" + data.Eimg +".png"} height="11px" width="20px" alt="employee" />
<div className="name"> {data.Eimg.png}</div>
</div>)
}
function onchange(args){
var maskObj = document.getElementById("mask").ej2_instances[0];
if(args.itemData.Country === 'United States'){
maskObj.mask = '(000)-000-0000';
maskObj.placeholder = '(000)-000-0000';
}
else if(args.itemData.Country === 'United Kingdom'){
maskObj.mask = '000-000-0000';
maskObj.placeholder = '000-000-0000'
}
else if(args.itemData.Country === 'Afghanistan'){
maskObj.mask = '000-000-0000';
maskObj.placeholder = '000-000-0000';
}
else if(args.itemData.Country === 'Albania'){
maskObj.mask = '000-000-0000';
maskObj.placeholder = '000-000-0000';
}
else if(args.itemData.Country === 'Algeria'){
maskObj.mask = '000-000-0000';
maskObj.placeholder = '000-000-0000';
}
maskObj.focusIn();
}
return (<div className="wrapper">
<DropDownListComponent change={onchange.bind(this)} id="ddlelement" valueTemplate={valueTemplate.bind(this)} itemTemplate={itemTemplate.bind(this)} width="auto" dataSource={data} fields={fields} index="0" popupHeight="250px" placeholder="Select an employee" popupWidth="400px" />
<MaskedTextBoxComponent id="mask" mask={'(000)-000-0000'} /></div>
);
}
export default App; |
|
.e-input-group-icon.e-ddl-icon.e-search-icon{
top: -4px;
}
.e-mask.e-input-group{
top: -35px;
left: 38px;
} |
Hi Berly
We are also looking this kind control.
Would you mind sharing the sample with Blazor controls.
Regards,
Anu
Hi Ponmani,
I'm also keen on a Blazor sample, Can you please provide an update?
Cheers,
Matt
Hi All,
We have recreated the above angular sample into the Blazor sample. Please find the code snippet and sample link below.
|
<SfDropDownList TValue="string" TItem="Countries" Width="50px" DataSource="Country" PopupWidth="300px" @bind-Value="val"> <DropDownListTemplates TItem="Countries"> <ItemTemplate> <div> <p><img className="empImage" src=https://flagcdn.com/16x12/@((context as Countries).Eimg).png height="11px" width="20px" alt="employee" /> @((context as Countries).Country) @((context as Countries).CountryCode)</p> </div> </ItemTemplate> <ValueTemplate> <div> <img className="empImage" src=https://flagcdn.com/16x12/@((context as Countries).Eimg).png height="11px" width="20px" alt="employee" /> </div> </ValueTemplate> </DropDownListTemplates> <DropDownListFieldSettings Value="Eimg"></DropDownListFieldSettings> <DropDownListEvents TValue="string" TItem="Countries" ValueChange="changeHandler"></DropDownListEvents> </SfDropDownList> <SfMaskedTextBox Mask="@maskvalue" Width="150px"></SfMaskedTextBox> @code{ public string maskvalue { get; set; } = "(000)-000-0000"; public string val { get; set; } = "us"; public class Countries { public string Eimg { get; set; } public string CountryCode { get; set; } public string Country { get; set; } } private List<Countries> Country = new List<Countries> { new Countries() { Eimg= "us", CountryCode= "+1", Country= "United States" }, new Countries() {Eimg= "gb", CountryCode= "+44", Country= "United Kingdom"}, new Countries() { Eimg= "af", CountryCode= "+93", Country= "Afghanistan" }, new Countries() {Eimg= "al", CountryCode= "+355", Country= "Albania"}, new Countries() {Eimg= "dz", CountryCode= "+213", Country= "Algeria" } }; void changeHandler(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, Countries> args) { switch (args.Value) { case "us": maskvalue = "(000)-000-0000"; break; case "gb": maskvalue = "000-000-0000"; break; case "af": maskvalue = "000-000-0000"; break; case "al": maskvalue = "000-000-0000"; break; case "dz": maskvalue = "000-000-0000"; break; } } } <style> .e-input-group-icon.e-ddl-icon.e-search-icon { top: -4px; }
.e-mask.e-input-group { top: -35px; left: 38px; }
.e-input-group, .e-input-group.e-control-wrapper { vertical-align: unset !important; } </style>
|
Regards,
Udhaya Kumar D
Thank you! This is great.
Hi Matthew,
Thanks for the update. We are glad to hear that the sample meets your requirement.
Regards,
Ponmani M