Commit 7ae35df1 authored by kezzle's avatar kezzle
Browse files

Merge branch 'i16-fix-region-validation' into 'main'

Validate the form even if the selected country has no region

Closes #16

See merge request !102
parents 24a15519 fbd29fc6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ include:

build:
  script:
    - apt-get install pip
    - if [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then
        export LEKTOR_ENV=prod;
      fi
Compare eed42198 to 5284cc1d
Original line number Diff line number Diff line
Subproject commit eed421981c7524670c61b0d5143f8670fa7631d5
Subproject commit 5284cc1dba0f05b9c979d055e408be954be9a75c
+18 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import {AppContext} from './app_context';
import {LoadingDialogReactPages} from './loading_dialog_react_pages';
import {FrequencySelector} from './frequency_selector';
import {determineBaseUrl} from './base_url';
import regions from './regions';

export function GivingForm(props) {
  const {frequencyOptions, pricesOnButtons, donateProccessorFallbackUrl, perks, initialSelectedPrices, defaultFrequencyForBoth, successRedirectUrl, shirtFits, showGifts, paymentMethods, stripePublishableKey} = props;
@@ -228,7 +229,23 @@ export function GivingForm(props) {
    const newErrors = [];
    const requiredFields = requiredFieldsForPerkAndPayment();
    for (const fieldName of requiredFields) {
      if (!validateField(formData, fieldName, isNotBlank)) {
      let validatorFunction = isNotBlank;

      // some countries don't have regions, form should validate if a user has selected a country with no regions
      // see: <https://gitlab.torproject.org/tpo/web/donate-static/-/issues/16>
      if (fieldName == 'region') {
          validatorFunction = (value) => {
              if (regions[formData.country]) {
                  return isNotBlank(value);
              } else {
                  // the formData has a `null` value for region. i think that's because the field is hidden
                  // set it to an empty string so stripe doesn't get angry
                  formData.region = '';
                  return true;
              }
          };
      }
      if (!validateField(formData, fieldName, validatorFunction)) {
        let placeholder = getFieldPlaceholder(fieldName);
        if (placeholder == null) {
          placeholder = fieldName;
+5 −1
Original line number Diff line number Diff line
@@ -13,7 +13,11 @@ export function RegionDropdown(props) {

  const regionsForCountry = regions[selectedCountry];
  if (regionsForCountry == undefined) {
    return null;
    return (
      <select id="region" name="region" className={`${classes.join(' ')} d-none`} onChange={onChange}>
        <option key="none" value=""></option>
      </select>
    );
  } else {
    let optionElements = [
      (<option key="none" value="">State</option>),

requirements.txt

0 → 100644
+10 −0
Original line number Diff line number Diff line
environs==9.5.0 \
  --hash=sha256:1e549569a3de49c05f856f40bce86979e7d5ffbbc4398e7f338574c220189124
marshmallow==3.19.0 \
  --hash=sha256:93f0958568da045b0021ec6aeb7ac37c81bfcccbb9a0e7ed8559885070b3a19b
packaging==21.3 \
  --hash=sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522
pyparsing==3.0.9 \
  --hash=sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc
python-dotenv==0.21.0 \
  --hash=sha256:1684eb44636dd462b66c3ee016599815514527ad99965de77f43e0944634a7e5