Skip to content

Commit

Permalink
Merge branch 'master' of github.com:formio/formio.js into fio4112
Browse files Browse the repository at this point in the history
  • Loading branch information
travist committed Apr 1, 2024
2 parents cd07d68 + 37b6beb commit 2d9bec2
Show file tree
Hide file tree
Showing 14 changed files with 365 additions and 62 deletions.
58 changes: 5 additions & 53 deletions .github/workflows/config.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,12 @@
# name: Build & Test

# on: push

# env:
# NODE_VERSION: 18.x

# jobs:
# test:
# runs-on: ubuntu-latest
# steps:
# - run: echo "Triggered by ${{ github.event_name }} event."

# - name: Check out repository code ${{ github.repository }} on ${{ github.ref }}
# uses: actions/checkout@v3

# - name: Set up Node.js ${{ env.NODE_VERSION }}
# uses: actions/setup-node@v3
# with:
# node-version: ${{ env.NODE_VERSION }}
# cache: 'npm'

# - name: Cache node modules
# uses: actions/cache@v3
# with:
# path: node_modules
# key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
# restore-keys: |
# ${{ runner.os }}-node-

# - name: Installing dependencies
# if: steps.cache.outputs.cache-hit != 'true'
# uses: borales/actions-yarn@v4
# with:
# cmd: install --frozen-lockfile

# - name: Lint
# uses: borales/actions-yarn@v4
# with:
# cmd: lint

# - name: Build
# uses: borales/actions-yarn@v4
# with:
# cmd: build

# - name: Test
# uses: borales/actions-yarn@v4
# with:
# cmd: test

name: Build & Test

on: push
on:
push:
branches:
- '*' # This will make sure all push events on any branch triggers this workflow.

env:
NODE_VERSION: 18.x
NODE_VERSION: 20.x

jobs:
setup:
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Release

on:
push:
tags:
- '*' # This will make sure tag creations also trigger the workflow.

env:
NODE_VERSION: 20.x
AWS_DEFAULT_REGION: us-west-2
AWS_ACCESS_KEY_ID: ${{ vars.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

jobs:
deploy_to_test:
# if: false
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest

steps:
- run: echo "Triggered by ${{ github.event_name }} event."
- name: Check out repository code ${{ github.repository }} on ${{ github.ref }}
uses: actions/checkout@v3

- name: Setup Ruby and Install Jekyll
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true

- name: Install Jekyll
run: gem install jekyll

- name: Restore node modules from cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install awscli
run: |
sudo apt-get update
sudo apt install -y awscli
- name: Release
uses: borales/actions-yarn@v4
with:
cmd: release
14 changes: 14 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,23 @@ Formio.createForm(document.getElementById('formio'), 'https://examples.form.io/e
- FIO-4871: fixed calculated value issues
- FIO 7603: fixed Edit Grid With Empty Rows Not Submitting Form
- FIO-7445: fixed an issue where the interpolated data does not show up on PDF
- FIO-7774: added validateWhenHidden option
- FIO-7421: Adds ReCaptcha error messages to the translations config
- FIO-7804: Added PKCE method for OIDC
- FIO-7675: Removed maps key from repo
- FIO-2453: Fixes an issue where custom disabled dates are not recalculated
- FIO-7395: Fixed the issue with loading nested form
- FIO-7996: refactor recaptcha validation
- FIO-7899: fixed an issue where saveDraft option does not work and added errors handling for the save draft and restore draft functionality
- FIO-7956: fixed an issue where simple condition based on stringified checkbox value is not executed correctly
- FIO-7933: added PDF Document Designer
- FIO-6632: update-formiojs-test-env-on-tag
- FIO-2453: Fixes an issue where custom disabled dates are bot recalculated after for valus is changed
- FIO-7395: Fixed the issue with loading nested form
- FIO-7807: added sanitizeConfig to global form settings
- FIO-7334: Fixes an issue where Radio values do not appear for Action Conditions settings
- FIO-8009: fixed display of the required asterisk
- FIO-8111: fixed saveDraft Trigger for nested forms

## 5.0.0-rc.37
### Fixed
Expand Down
35 changes: 34 additions & 1 deletion src/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,38 @@ export default class Form extends Element {
};
}

/**
* Check Subdirectories path and provide correct options
*
* @param {string} url - The the URL of the form json.
* @param {form} object - The form json.
* @return {object} The initial options with base and project.
*/
getFormInitOptions(url, form) {
const options = {};
const index = url.indexOf(form?.path);
// form url doesn't include form path
if (index === -1) {
return options;
}
const projectUrl = url.substring(0, index - 1);
const urlParts = Formio.getUrlParts(projectUrl);
// project url doesn't include subdirectories path
if (!urlParts || urlParts.filter(part => !!part).length < 4) {
return options;
}
const baseUrl = `${urlParts[1]}${urlParts[2]}`;
// Skip if baseUrl has already been set
if (baseUrl !== Formio.baseUrl) {
return {
base: baseUrl,
project: projectUrl,
};
}

return {};
}

setForm(formParam) {
let result;
formParam = formParam || this.form;
Expand All @@ -185,7 +217,8 @@ export default class Form extends Element {
}
this.loading = false;
this.instance = this.instance || this.create(form.display);
this.instance.url = formParam;
const options = this.getFormInitOptions(formParam, form);
this.instance.setUrl(formParam, options);
this.instance.nosubmit = false;
this._form = this.instance.form = form;
if (submission) {
Expand Down
42 changes: 42 additions & 0 deletions src/Formio.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2222,6 +2222,48 @@ describe('Formio.js Tests', () => {
];
}
},
{
name: 'Should return correct options for form url with Subdirectories path',
test() {
let form = new Formio.Form();
let options = form.getFormInitOptions('http://localhost:3000/fakeproject/fakeform', { path: 'fakeform' });
assert.deepEqual(options, {
base: 'http://localhost:3000',
project: 'http://localhost:3000/fakeproject',
});

form = new Formio.Form();
options = form.getFormInitOptions(`${Formio.baseUrl}/fakeproject/fakeform`, { path: 'fakeform' });
assert.deepEqual(options, {});
}
},
{
name: 'Should set correct formio base and project url for form with Subdirectories path',
test() {
const formElement = document.createElement('div');
return Formio.createForm(formElement, 'http://localhost:3000/fakeproject/fakeform')
.then((form) => {
assert.equal(form.formio.base, 'http://localhost:3000');
assert.equal(form.formio.projectUrl, 'http://localhost:3000/fakeproject');
});
},
mock() {
return {
url: 'http://localhost:3000/fakeproject/fakeform',
method: 'GET',
response() {
return {
headers: {
'Content-Type': 'application/json',
},
body: {
path: 'fakeform',
}
};
}
};
},
},
];

tests.forEach(testCapability);
Expand Down
19 changes: 18 additions & 1 deletion src/WebformBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export default class WebformBuilder extends Component {
html,
disableBuilderActions: self?.component?.disableBuilderActions,
childComponent: component,
design: self?.options?.design
});
};

Expand Down Expand Up @@ -560,6 +561,7 @@ export default class WebformBuilder extends Component {
attach(element) {
this.on('change', (form) => {
this.populateRecaptchaSettings(form);
this.webform.setAlert(false);
});
return super.attach(element).then(() => {
this.loadRefs(element, {
Expand Down Expand Up @@ -945,6 +947,21 @@ export default class WebformBuilder extends Component {
}
}

if (draggableComponent.uniqueComponent) {
let isCompAlreadyExists = false;
eachComponent(this.webform.components, (component) => {
if (component.key === draggableComponent.schema.key) {
isCompAlreadyExists = true;
return;
}
}, true);
if (isCompAlreadyExists) {
this.webform.redraw();
this.webform.setAlert('danger', `You cannot add more than one ${draggableComponent.title} component to one page.`);
return;
}
}

if (target !== source) {
// Ensure the key remains unique in its new container.
BuilderUtils.uniquify(this.findNamespaceRoot(target.formioComponent), info);
Expand Down Expand Up @@ -982,7 +999,7 @@ export default class WebformBuilder extends Component {

const componentInDataGrid = parent.type === 'datagrid';

if (isNew && !this.options.noNewEdit && !info.noNewEdit) {
if (isNew && !this.options.noNewEdit && !info.noNewEdit && !(this.options.design && info.type === 'reviewpage')) {
this.editComponent(info, target, isNew, null, null, { inDataGrid: componentInDataGrid });
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/datagrid/DataGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export default class DataGridComponent extends NestedArrayComponent {
}

get canAddColumn() {
return this.builderMode;
return this.builderMode && !this.options.design;
}

render() {
Expand Down
31 changes: 30 additions & 1 deletion src/components/datetime/DateTime.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DateTimeComponent from './DateTime';
import { Formio } from './../../Formio';
import _ from 'lodash';
import 'flatpickr';
import moment from 'moment';
import {
comp1,
comp2,
Expand All @@ -15,7 +16,8 @@ import {
// comp9,
comp10,
comp11,
comp12
comp12,
comp13,
} from './fixtures';

describe('DateTime Component', () => {
Expand Down Expand Up @@ -702,6 +704,33 @@ describe('DateTime Component', () => {
}).catch(done);
});

it('Should refresh disabled dates when other fields values change', (done) => {
const form = _.cloneDeep(comp13);
const element = document.createElement('div');

Formio.createForm(element, form).then(form => {
const minDate = form.getComponent('minDate');
const maxDate = form.getComponent('maxDate');
minDate.setValue(moment().startOf('month').toISOString());
maxDate.setValue(moment().startOf('month').add(7, 'days').toISOString());

setTimeout(() => {
const inBetweenDate = form.getComponent('inBetweenDate');
const calendar = inBetweenDate.element.querySelector('.flatpickr-input').widget.calendar;
assert.equal(calendar.days.querySelectorAll('.flatpickr-disabled').length, 36, 'Only dates between selected' +
' min and max dates should be enabled');

maxDate.setValue(moment().startOf('month').add(10, 'days').toISOString(), { modified: true });
setTimeout(() => {
assert.equal(calendar.days.querySelectorAll('.flatpickr-disabled').length, 33, 'Should recalculate' +
' disabled dates after value change');

done();
}, 400);
}, 400);
}).catch(done);
});

// it('Should provide correct date in selected timezone after submission', (done) => {
// const form = _.cloneDeep(comp9);
// const element = document.createElement('div');
Expand Down
Loading

0 comments on commit 2d9bec2

Please sign in to comment.