Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getValidatorFn = function getValidatorFn(validator) {
// Validator has been passed as a function so just return it
if (is.function(validator)) {
return validator
}
// Validator has been passed as a string (i.e. 'isLength'), try to find the validator is validator.js or custom validators
if (is.string(validator) && !is.empty(validator)) {
return validatorjs[validator] || customValidators[validator] || undefined
}
}
checkForErrors = () => {
let hasError = [...this.state.hasError];
const { radioId, noFeedbackId } = this.props;
const { feedbackChoice, formSubmitted } = this.state;
// The user has not selected yes or no.
if (!hasError.includes(radioId) && feedbackChoice === null) {
hasError.push(radioId);
}
if (hasError.includes(radioId) && !is.nil(feedbackChoice)) {
hasError = this.removeError(hasError, radioId);
}
// The user has selected no but has not typed any feedback.
if (!hasError.includes(noFeedbackId) && feedbackChoice === false && formSubmitted && is.empty(this.noTextArea.current.value)) {
hasError.push(noFeedbackId);
} else if (hasError.includes(noFeedbackId) && feedbackChoice === false && !is.empty(this.noTextArea.current.value)) {
hasError = this.removeError(hasError, noFeedbackId);
}
// If the user changed choices from no to yes, remove the error for no if there was one.
if (feedbackChoice === true && hasError.includes(noFeedbackId)) {
hasError = this.removeError(hasError, noFeedbackId);
}
// Prevent calling setState too often while typing in textareas.
if (!is.equal(hasError, this.state.hasError)) {
this.setState({ hasError });
}
return hasError;
};
handleSubmit = (e) => {
Amplitude.prototype.identify = function(identify) {
this.setDeviceIdFromAnonymousId(identify);
var id = identify.userId();
var traits = identify.traits();
if (id) window.amplitude.getInstance().setUserId(id);
// map query params from context url if opted in
var mapQueryParams = this.options.mapQueryParams;
var query = identify.proxy('context.page.search');
if (!is.empty(mapQueryParams)) {
// since we accept any arbitrary property name and we dont have conditional UI components
// in the app where we can limit users to only add a single mapping, so excuse the temporary jank
each(function(value, key) {
traits[key] = query;
}, mapQueryParams);
}
this.setTraits(traits);
// Set user groups: https://amplitude.zendesk.com/hc/en-us/articles/115001361248#setting-user-groups
var groups = identify.options(this.name).groups;
if (groups && is.object(groups)) {
for (var group in groups) {
if (groups.hasOwnProperty(group))
window.amplitude.getInstance().setGroup(group, groups[group]);
}
var query;
if (props.link_query) {
query = props.link_query; // DOM query
delete props.link_query;
window.mixpanel.track_links(query, track.event(), props);
} else if (props.form_query) {
// DOM query
query = props.form_query;
delete props.form_query;
window.mixpanel.track_forms(query, track.event(), props);
} else {
window.mixpanel.track(track.event(), props);
}
// register super properties if present in context.mixpanel.superProperties
if (!is.empty(superProps)) {
window.mixpanel.register(superProps);
}
};
checkForErrors = () => {
let hasError = [...this.state.hasError];
const { radioId, noFeedbackId } = this.props;
const { feedbackChoice, formSubmitted } = this.state;
// The user has not selected yes or no.
if (!hasError.includes(radioId) && feedbackChoice === null) {
hasError.push(radioId);
}
if (hasError.includes(radioId) && !is.nil(feedbackChoice)) {
hasError = this.removeError(hasError, radioId);
}
// The user has selected no but has not typed any feedback.
if (!hasError.includes(noFeedbackId) && feedbackChoice === false && formSubmitted && is.empty(this.noTextArea.current.value)) {
hasError.push(noFeedbackId);
} else if (hasError.includes(noFeedbackId) && feedbackChoice === false && !is.empty(this.noTextArea.current.value)) {
hasError = this.removeError(hasError, noFeedbackId);
}
// If the user changed choices from no to yes, remove the error for no if there was one.
if (feedbackChoice === true && hasError.includes(noFeedbackId)) {
hasError = this.removeError(hasError, noFeedbackId);
}
// Prevent calling setState too often while typing in textareas.
if (!is.equal(hasError, this.state.hasError)) {
this.setState({ hasError });
}
return hasError;
};
handleSubmit = (e) => {
Criteo.prototype.page = function(page) {
var homeUrl = this.options.homeUrl;
var pageName = (page.name() || '').toLowerCase();
var path = page.path();
var url = page.url();
var event = [{ event: 'viewHome' }];
var payload = [];
var supportingPageData = this.options.supportingPageData;
var properties = page.properties(this.options.supportingPageData);
var extraData = pick(values(supportingPageData), properties);
if (!is.empty(extraData)) {
window.criteo_q.push(extend(extraData, { event: 'setData' }));
}
if (url === homeUrl || pageName === 'home' || path === '/') {
payload = event.concat(this.setExtraData(page));
window.criteo_q.push.apply(window.criteo_q, payload);
}
};
handleChange = (e) => {
e.persist();
const { value } = e.target;
if (is.empty(value)) {
const suggestions = this.optionsToSuggestions(this.props.options);
if (this.props.renderDefaultSuggestion) {
this.setState({
suggestions,
value: ''
}, () => {
if (is.fn(this.props.onChange)) {
this.props.onChange({ event: e, value, suggestions });
}
});
} else if (is.fn(this.props.onChange)) {
this.props.onChange({ event: e, value, suggestions });
}
} else {
const suggestions = this.fuse.search(value);
this.setState({
const handleFocus = () => {
const inputEl = ref.current;
if (is.empty(inputEl.value)) {
inputEl.removeAttribute('placeholder');
}
};
return annotations.map(function(annotation, index) {
var detectionType = types[index];
var typeName = typeShortNameToRespName[detectionType];
if (is.empty(annotation) || annotation.error) {
var isPlural = typeName.charAt(typeName.length - 1) === 's';
annotation[typeName] = isPlural ? [] : {};
}
return annotation;
});
}