Skip to content

Commit

Permalink
Merge pull request #1725 from yadvirkaur/baniController
Browse files Browse the repository at this point in the history
fix hyphen issue for sync and controller code
  • Loading branch information
yadvirkaur authored Aug 21, 2024
2 parents 40d8c64 + 14df762 commit c082f0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/js/pages/Sync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,13 @@ class Sync extends React.PureComponent {
onKeyUp={e => {
const typedValue = e.currentTarget.value;
const typedChar = e.key;
const hasHyphen = typedValue.includes('-');
const parsedValue = typedValue.match('^[A-Z,a-z]{3}');
const d = parsedValue ? parsedValue[0] === typedValue : false;
if (d && typedChar !== 'Backspace') {
e.currentTarget.value = typedValue + '-';
} else if (typedChar === '-' && hasHyphen) {
e.currentTarget.value = typedValue.replace(/[-]+/g, '-');
}
}}
/>
Expand Down
31 changes: 11 additions & 20 deletions src/js/pages/WebController/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { Stub } from '../Search/Layout';
import ControllerShabad from '@/pages/WebController/shabad';
import { versesToGurbani } from '@/util';
import ShabadControls from '@/components/ShabadControls';
import { isMobile } from 'react-device-detect';
export default class WebControllerPage extends React.PureComponent {
constructor(props) {
super(props);
Expand Down Expand Up @@ -274,26 +273,18 @@ export default class WebControllerPage extends React.PureComponent {
pattern="[A-Z,a-z]{3}-[A-Z,a-z]{3}"
onKeyUp={e => {
const typedValue = e.currentTarget.value;
if (isMobile) {
const parsedValue = typedValue.match('^[A-Z,a-z]{4}');
const isParsedValueExist = parsedValue
? parsedValue[0] === typedValue
: false;
if (isParsedValueExist) {
const lastChar = typedValue.slice(-1);
e.currentTarget.value =
typedValue.slice(0, 3) + '-' + lastChar;
}
} else {
const typedChar = e.key;
const parsedValue = typedValue.match('^[A-Z,a-z]{3}');
const isParsedValueExist = parsedValue
? parsedValue[0] === typedValue
: false;
if (isParsedValueExist && typedChar !== 'Backspace') {
e.currentTarget.value = typedValue + '-';
}
const typedChar = e.key;
const hasHyphen = typedValue.includes('-');
const parsedValue = typedValue.match('^[A-Z,a-z]{3}');
const isParsedValueExist = parsedValue
? parsedValue[0] === typedValue
: false;
if (isParsedValueExist && typedChar !== 'Backspace') {
e.currentTarget.value = typedValue + '-';
} else if (typedChar === '-' && hasHyphen) {
e.currentTarget.value = typedValue.replace(/[-]+/g, '-');
}

}}
required
/>
Expand Down

0 comments on commit c082f0f

Please sign in to comment.