spz-phonenumber
Layouts
跳转到“Layouts”Usage
跳转到“Usage”If you want display country or province, you can use spz-area
, and spz-phonenumber
set visible-id
, visible-rule
attribute, and spz-phonenumber
add action input
to update spz-area
.
If you want display country flag, you can use spz-render
, and spz-area
add action to rerender in spz-render
.
<spz-phonenumber
id="phone-number"
layout="container"
visible-id="phone-area-container"
visible-rule="[\+0-9\(\).\s-]+"
default-country="countryCode"
default-phone="countryPhoneArea"
@input="phone-area.update(code=event.code);"
keep-chart
>
<input
class="form__input"
id="phone"
name="phone"
type="text"
tabindex="1"
required
pattern="[\+0-9\(\).\s-]+"
@input-debounced="form-tips.toggleClass(class='form-tips-visible', force=false);"
@change="order-view-form.insert(name='email', value=event.value);order-view-form.insert(name='phone', value=event.value);"
>
<label class="form__label" for="phone">Phone</label>
</spz-phonenumber>
<div id="phone-area-container" class="flex items-center" hidden>
<spz-area id="phone-area" src="script:phone-area-json" @areaChange="phone-number.update(data=event.data);" @update="phone-nation-flag.rerender(data=event.data);" layout="container" areacode>
<select>
<option empty value disabled>*</option>
</select>
</spz-area>
<spz-render id="phone-nation-flag" layout="container">
<template>
<div>
<!-- ... -->
<div class="flag" style="background-image: url(${data.flag});"></div>
</div>
</template>
</spz-render>
</div>
Attributes
跳转到“Attributes”visible-rule
跳转到“visible-rule”Display the country and flag parent element by visible rule, such as [\+0-9\(\).\s-]+
visible-id
跳转到“visible-id”The id of the country and flag parent element.
default-country
跳转到“default-country”Default country code When the phone number does not match the country code.
default-phone
跳转到“default-phone”Default phonenumber When the country code does not match the phone number.
keep-chart
跳转到“keep-chart”If this attribute is present, remove ()
or -
for validation.
Actions
跳转到“Actions”update
跳转到“update”update(data=<Object>)
The update
action updated phone code and format phonenumber
Events
跳转到“Events”The following spz-phonenumber
events trigger on input when they’re
input
input
跳转到“input”The input
event triggers the targeted spz-phonenumber
input to change . change data is countryCode
example . @input="phone-area.update(code=event.code);"