2016-08-02 15:23:09 -04:00
|
|
|
var allCountries = require('react-telephone-input/lib/country_data').allCountries;
|
2016-06-02 15:25:02 -04:00
|
|
|
var classNames = require('classnames');
|
2016-08-02 15:23:09 -04:00
|
|
|
var ComponentMixin = require('formsy-react-components').ComponentMixin;
|
2016-06-02 15:25:02 -04:00
|
|
|
var FormsyMixin = require('formsy-react').Mixin;
|
2016-08-02 15:23:09 -04:00
|
|
|
var React = require('react');
|
2016-06-02 15:25:02 -04:00
|
|
|
var ReactPhoneInput = require('react-telephone-input/lib/withStyles');
|
|
|
|
var Row = require('formsy-react-components').Row;
|
2016-08-02 15:23:09 -04:00
|
|
|
|
|
|
|
var defaultValidationHOC = require('./validations.jsx').defaultValidationHOC;
|
2016-06-13 12:48:58 -04:00
|
|
|
var inputHOC = require('./input-hoc.jsx');
|
2016-08-02 15:23:09 -04:00
|
|
|
var intl = require('../../lib/intl.jsx');
|
|
|
|
var validationHOCFactory = require('./validations.jsx').validationHOCFactory;
|
2016-06-02 15:25:02 -04:00
|
|
|
|
2016-06-03 11:28:04 -04:00
|
|
|
var allIso2 = allCountries.map(function (country) {return country.iso2;});
|
2016-06-03 00:01:46 -04:00
|
|
|
|
2016-06-13 12:48:58 -04:00
|
|
|
require('./row.scss');
|
2016-06-23 07:27:43 -04:00
|
|
|
require('./phone-input.scss');
|
2016-06-13 12:48:58 -04:00
|
|
|
|
2016-06-02 15:25:02 -04:00
|
|
|
var PhoneInput = React.createClass({
|
|
|
|
displayName: 'PhoneInput',
|
|
|
|
mixins: [
|
|
|
|
FormsyMixin,
|
|
|
|
ComponentMixin
|
|
|
|
],
|
|
|
|
getDefaultProps: function () {
|
|
|
|
return {
|
|
|
|
validations: {
|
2016-08-02 15:23:09 -04:00
|
|
|
isPhone: true,
|
|
|
|
phoneLength: true
|
2016-06-02 15:25:02 -04:00
|
|
|
},
|
2016-06-03 00:01:46 -04:00
|
|
|
flagsImagePath: '/images/flags.png',
|
|
|
|
defaultCountry: 'us'
|
2016-06-02 15:25:02 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
onChangeInput: function (number, country) {
|
|
|
|
var value = {national_number: number, country_code: country};
|
|
|
|
this.setValue(value);
|
|
|
|
this.props.onChange(this.props.name, value);
|
|
|
|
},
|
|
|
|
render: function () {
|
2016-06-03 00:01:46 -04:00
|
|
|
var defaultCountry = PhoneInput.getDefaultProps().defaultCountry;
|
|
|
|
if (allIso2.indexOf(this.props.defaultCountry.toLowerCase()) !== -1) {
|
|
|
|
defaultCountry = this.props.defaultCountry.toLowerCase();
|
|
|
|
}
|
2016-06-02 15:25:02 -04:00
|
|
|
return (
|
|
|
|
<Row {... this.getRowProperties()}
|
|
|
|
htmlFor={this.getId()}
|
2016-07-25 15:43:44 -04:00
|
|
|
rowClassName={classNames('phone-input', this.props.className)}
|
2016-06-02 15:25:02 -04:00
|
|
|
>
|
|
|
|
<div className="input-group">
|
|
|
|
<ReactPhoneInput className="form-control"
|
|
|
|
{... this.props}
|
2016-06-03 00:01:46 -04:00
|
|
|
defaultCountry={defaultCountry}
|
2016-06-02 15:25:02 -04:00
|
|
|
onChange={this.onChangeInput}
|
|
|
|
id={this.getId()}
|
|
|
|
label={null}
|
|
|
|
disabled={this.isFormDisabled() || this.props.disabled}
|
|
|
|
/>
|
2016-07-26 08:06:38 -04:00
|
|
|
{this.renderHelp()}
|
2016-07-25 15:43:44 -04:00
|
|
|
{this.renderErrorMessage()}
|
2016-06-02 15:25:02 -04:00
|
|
|
</div>
|
|
|
|
</Row>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var phoneValidationHOC = validationHOCFactory({
|
2016-08-02 15:23:09 -04:00
|
|
|
isPhone: <intl.FormattedMessage id="teacherRegistration.validationPhoneNumber" />,
|
|
|
|
phoneLength: <intl.FormattedMessage id="teacherRegistration.validationPhoneNumber" />
|
2016-06-02 15:25:02 -04:00
|
|
|
});
|
|
|
|
|
2016-06-13 12:48:58 -04:00
|
|
|
module.exports = inputHOC(defaultValidationHOC(phoneValidationHOC(PhoneInput)));
|