Skip to content

Commit

Permalink
Merge pull request #5672 from formio/FIO-8304-multiple-mask-left-empty
Browse files Browse the repository at this point in the history
FIO-8304: allow for multivalue masks to have blank input mask option
  • Loading branch information
brendanbond authored Jul 5, 2024
2 parents 6e2d384 + 279701a commit 14e7d74
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/components/_classes/multivalue/Multivalue.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,17 @@ export default class Multivalue extends Field {

/**
* @param {any} input - The input element on which the mask is to be applied.
* @param {string} mask - The mask pattern to apply to the input element. Exit early if no mask.
* @param {string} mask - The mask pattern to apply to the input element. Exit early and remove previous mask if no mask.
*/
updateMask(input, mask) {
if (!mask) {
if (input.mask) {
input.mask.destroy();
}
if (!this.component.placeholder) {
input.removeAttribute('placeholder');
}
input.value = '';
return;
}
this.setInputMask(input, mask, !this.component.placeholder);
Expand Down
15 changes: 15 additions & 0 deletions src/components/phonenumber/PhoneNumber.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Formio } from './../../Formio';

import {
comp1,
comp2
} from './fixtures';

describe('PhoneNumber Component', () => {
Expand Down Expand Up @@ -55,4 +56,18 @@ describe('PhoneNumber Component', () => {
})
.catch(done);
});

it('Should remove previous input mask when switching to a blank input mask', (done) => {
Formio.createForm(document.createElement('div'), comp2, {}).then((form) => {
const phoneNumberComponent = form.getComponent('phoneNumber');
const changeEvent = new Event('change');
phoneNumberComponent.refs.select[0].value = "Other";
phoneNumberComponent.refs.select[0].dispatchEvent(changeEvent);
setTimeout(()=>{
assert.equal(phoneNumberComponent.refs.input[0].querySelector('input').value, "");
assert.equal(phoneNumberComponent.refs.input[0].querySelector('input').getAttribute('placeholder'), null);
done();
},200);
});
});
});
23 changes: 23 additions & 0 deletions src/components/phonenumber/fixtures/comp2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default {
components: [
{
"label": "Phone Number",
"applyMaskOn": "change",
"allowMultipleMasks": true,
"tableView": true,
"key": "phoneNumber",
"type": "phoneNumber",
"inputMasks": [
{
"label": "Canada",
"mask": "(999) 999-9999"
},
{
"label": "Other",
"mask": ""
}
],
"input": true
}
]
}
3 changes: 2 additions & 1 deletion src/components/phonenumber/fixtures/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import comp1 from './comp1';
export { comp1 };
import comp2 from './comp2'
export { comp1, comp2 };

0 comments on commit 14e7d74

Please sign in to comment.