-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#360250: add pin element #104
Open
Sophiaw-hub
wants to merge
9
commits into
main
Choose a base branch
from
features/swl/pin-element
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+452
−3
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2ea9b07
Bump intl-tel-input from 19.5.7 to 21.2.7
dependabot[bot] 30b870f
add pin element plus container
9ab255d
wip
8c1d7aa
style configs auto submit
b834019
validation, testing
c9529f0
combine container- and input-pin to one element
97ee5e9
code adjustment, remove tooltip
48714cb
auto focus first input
5c40baa
pin styling
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const {cx} = require('@bsi-cx/design-build'); | ||
|
||
module.exports = cx.style | ||
.withIdentifier('pin-auto-submit-ae00c3ca') | ||
/*.withLabel('Pin auto submit')*/ | ||
.withLabel('automatisch versenden ') | ||
.withCssClasses( | ||
cx.cssClass | ||
/*.withLabel('No auto submit')*/ | ||
.withLabel('nein') | ||
.withCssClass('default'), | ||
cx.cssClass | ||
/*.withLabel('Show auto submit')*/ | ||
.withLabel('ja') | ||
.withCssClass('auto-submit')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const {cx} = require('@bsi-cx/design-build'); | ||
|
||
module.exports = cx.style | ||
.withIdentifier('pin-label-numbering-ba3c80c7') | ||
/*.withLabel('Numbered label')*/ | ||
.withLabel('Nummerierung') | ||
.withCssClasses( | ||
cx.cssClass | ||
/*.withLabel('Show numbering')*/ | ||
.withLabel('Mit Nummerierung') | ||
.withCssClass('pin-label-visible'), | ||
cx.cssClass | ||
/*.withLabel('No numbering')*/ | ||
.withLabel('Ohne Nummerierung') | ||
.withCssClass('pin-label-invisible')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const advancedElements = [ | ||
require('./webcam-image-upload') | ||
require('./webcam-image-upload'), | ||
]; | ||
|
||
module.exports.advancedElements = advancedElements; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import Alpine from '@alpinejs/csp'; | ||
|
||
Alpine.data('formPin', () => ({ | ||
bsiInputElement: null, // Input field required for CX story / value flow | ||
maxLength: null, | ||
requiredErrorElement: null, | ||
form: null, | ||
root: null, | ||
|
||
initForm() { | ||
this.form = this.$el; | ||
this.root = this.$root; | ||
|
||
if (this.root.classList.contains('bsi-form-label-floating')) { | ||
for(const floatingElement of this.form.getElementsByClassName('bsi-label-floating-element')) { | ||
this._initFloatingLabels(floatingElement); | ||
} | ||
} | ||
}, | ||
|
||
submitForm(e) { | ||
if (!this.form.checkValidity()) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
this.validateInput(); | ||
} | ||
this.form.classList.add('was-validated'); | ||
}, | ||
|
||
initRequiredError() { | ||
this.requiredErrorElement = this.$el; | ||
}, | ||
|
||
validateInput() { | ||
if (this.bsiInputElement.value.length != this.maxLength) { | ||
this.requiredErrorElement.style.display = "block"; | ||
} else { | ||
this.requiredErrorElement.style.display = "none"; | ||
} | ||
}, | ||
|
||
initPinNumberFields() { | ||
this.bsiInputElement = this.$root.querySelector('.bsi-form-field-input-original'); | ||
let containerDiv = this.$root.querySelector('.bsi-form-pin-element'); | ||
|
||
this.maxLength = this.bsiInputElement.getAttribute('maxlength') ?? 6; | ||
for (let i = 0; i < this.maxLength; i++) { | ||
this._initPinNumberField(containerDiv, i); | ||
} | ||
this._autoFocusFirstPinInput(); | ||
}, | ||
|
||
_initPinNumberField(containerDiv, i) { | ||
let div = document.createElement('div'); | ||
let label = document.createElement('label'); | ||
let inputPin = document.createElement('input'); | ||
|
||
div.classList = 'input-wrapper'; | ||
label.classList = 'form-label'; | ||
label.innerHTML = (i + 1) + "."; | ||
inputPin.classList = 'bsi-form-field-input form-control bsi-form-field-input pin'; | ||
|
||
inputPin.setAttribute('required', 'true'); | ||
inputPin.setAttribute('inputmode', 'numeric'); | ||
inputPin.setAttribute('type', "number"); | ||
|
||
div.appendChild(label); | ||
div.appendChild(inputPin); | ||
containerDiv.appendChild(div); | ||
|
||
inputPin.addEventListener('focusin', (e) => { | ||
inputPin.setAttribute('old', inputPin.value); | ||
}); | ||
|
||
inputPin.addEventListener('keydown', (e) => { | ||
if ((e.key =='Backspace') && !inputPin.value) { | ||
this._autoFocusPreviousPinInput(inputPin); | ||
} | ||
}); | ||
|
||
inputPin.addEventListener('input', (e) => { | ||
const inputPinList = this.$root.querySelectorAll('input.pin'); | ||
this._cleanUp(inputPin); | ||
this.bsiInputElement.value = Array.from(inputPinList).reduce((result, input) => { | ||
return result + input.value; | ||
}, ""); | ||
if (this.$root.classList.contains('auto-submit')) { | ||
this._autoSubmitIfFilledIn(); | ||
} | ||
this._autoFocusNextPinInput(inputPin); | ||
}); | ||
}, | ||
|
||
_autoFocusFirstPinInput() { | ||
let wrapper = this.$root.querySelectorAll('.input-wrapper'); | ||
this._autoFocus(wrapper[0]); | ||
}, | ||
|
||
_autoFocusNextPinInput(inputPin) { | ||
let nextWrapper = inputPin.parentNode.nextElementSibling; | ||
if (inputPin.value && !this._isLastPinElement(inputPin)) { | ||
this._autoFocus(nextWrapper); | ||
} | ||
}, | ||
|
||
_autoFocusPreviousPinInput(inputPin) { | ||
let previousWrapper = inputPin.parentNode.previousSibling; | ||
if (previousWrapper != null) { | ||
this._autoFocus(previousWrapper); | ||
} | ||
}, | ||
|
||
_autoFocus(wrapper){ | ||
var nextPinInput = wrapper.querySelector('input.pin'); | ||
if (nextPinInput) { | ||
nextPinInput.focus(); | ||
} | ||
}, | ||
|
||
_autoSubmitIfFilledIn() { | ||
let form = this.$root.querySelector('.formular-pin'); | ||
if (form && (this.bsiInputElement.value.length == this.maxLength)) { | ||
form.submit(); | ||
} | ||
}, | ||
|
||
_cleanUp(inputPin) { | ||
if (inputPin.value) { | ||
if (this._isLastPinElement(inputPin)){ | ||
inputPin.value = inputPin.value.slice(-1); | ||
} else if (inputPin.value.length > 1) { | ||
var oldValue = inputPin.getAttribute('old'); | ||
var newValue = inputPin.value.replace(oldValue, ''); | ||
inputPin.value = newValue; | ||
oldValue = newValue; | ||
} | ||
} | ||
}, | ||
|
||
_isLastPinElement(inputPin) { | ||
return inputPin.parentNode.nextElementSibling == null; | ||
}, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require('./styles.scss'); | ||
const {cx, Icon} = require('@bsi-cx/design-build'); | ||
|
||
const element = cx.contentElement; | ||
|
||
/** | ||
* @returns {ContentElement} | ||
*/ | ||
module.exports = element; | ||
element.withFile(require('./template.twig')) | ||
.withElementId('form-container-pin-384aa4d6') | ||
/*.withLabel('Form')*/ | ||
.withLabel('Pin-Element') | ||
.withIcon(Icon.ONE_COLUMN) | ||
.withStyleConfigs( | ||
require('../../../configs/styles/form-width'), | ||
require('../../../configs/styles/form-layout'), | ||
require('../../../configs/styles/form-color'), | ||
require('../../../configs/styles/pin-label'), | ||
require('../../../configs/styles/pin-auto-submit')) | ||
.withParts( | ||
cx.part.formField | ||
.withId('form-field-part-eefc3ac5') | ||
.withLabel('Formularfeld'), | ||
cx.part.plainText | ||
.withId('form-field-part-text-cc1a1c62') | ||
.withLabel('Info Text'), | ||
cx.part.plainText | ||
.withId('form-field-part-error-required-f3cf3728') | ||
.withLabel('Fehlermeldung bei leerem Pflichtfeld')); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Event Listener kannst du auch mit
setAttribute('@focusin', 'myAlpineFunction')
registrierenThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ich bekomme das auf diesen Weg leider nicht hin. Generell, sobald ich versuche, die Methode auszulagern. Wird das Event nicht mehr erkannt.