diff --git a/client/src/components/formHelpers/Form.js b/client/src/components/formHelpers/Form.js index 809ddfc6d2..2965db9e72 100644 --- a/client/src/components/formHelpers/Form.js +++ b/client/src/components/formHelpers/Form.js @@ -21,6 +21,7 @@ const propTypes = { initialValues: PropTypes.object, options: PropTypes.shape({ ignored: PropTypes.arrayOf(PropTypes.string), + isEditorLinkAllowed: PropTypes.bool, required: PropTypes.arrayOf(PropTypes.string), types: PropTypes.objectOf(PropTypes.string) }), diff --git a/client/src/components/formHelpers/FormFields.js b/client/src/components/formHelpers/FormFields.js index c249b456e1..83d1d20357 100644 --- a/client/src/components/formHelpers/FormFields.js +++ b/client/src/components/formHelpers/FormFields.js @@ -24,6 +24,7 @@ const propTypes = { ).isRequired, options: PropTypes.shape({ ignored: PropTypes.arrayOf(PropTypes.string), + isEditorLinkAllowed: PropTypes.bool, placeholders: PropTypes.objectOf(PropTypes.string), required: PropTypes.arrayOf(PropTypes.string), types: PropTypes.objectOf(PropTypes.string) @@ -36,7 +37,8 @@ function FormFields(props) { ignored = [], placeholders = {}, required = [], - types = {} + types = {}, + isEditorLinkAllowed = false } = options; const nullOrWarning = (value, error, isURL, name) => { @@ -49,7 +51,7 @@ function FormFields(props) { } } const validationWarning = composeValidators( - name === 'githubLink' ? null : editorValidator, + name === 'githubLink' || isEditorLinkAllowed ? null : editorValidator, localhostValidator )(value); const message = error || validationError || validationWarning; diff --git a/client/src/components/formHelpers/index.js b/client/src/components/formHelpers/index.js index 0d274a7612..e12593a309 100644 --- a/client/src/components/formHelpers/index.js +++ b/client/src/components/formHelpers/index.js @@ -15,17 +15,18 @@ const normalizeOptions = { }; export function formatUrlValues(values, options) { + const { isEditorLinkAllowed, types } = options; const validatedValues = { values: {}, errors: [], invalidValues: [] }; const urlValues = Object.keys(values).reduce((result, key) => { let value = values[key]; const nullOrWarning = composeValidators( localhostValidator, - key === 'githubLink' ? null : editorValidator + key === 'githubLink' || isEditorLinkAllowed ? null : editorValidator )(value); if (nullOrWarning) { validatedValues.invalidValues.push(nullOrWarning); } - if (value && options.types[key] === 'url') { + if (value && types[key] === 'url') { try { value = normalizeUrl(value, normalizeOptions); } catch (err) { diff --git a/client/src/templates/Challenges/projects/SolutionForm.js b/client/src/templates/Challenges/projects/SolutionForm.js index baed7034ab..a413fda5b7 100644 --- a/client/src/templates/Challenges/projects/SolutionForm.js +++ b/client/src/templates/Challenges/projects/SolutionForm.js @@ -58,7 +58,8 @@ export class SolutionForm extends Component { solution: 'url', githubLink: 'url' }, - required: ['solution'] + required: ['solution'], + isEditorLinkAllowed: false }; const buttonCopy = isSubmitting @@ -89,6 +90,7 @@ export class SolutionForm extends Component { case pythonProject: formFields = solutionField; + options.isEditorLinkAllowed = true; solutionLink = solutionLink + (description.includes('Colaboratory')