import * as React from 'react'; import JqxButton from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxbuttons'; import JqxCheckBox from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxcheckbox'; import JqxListBox from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxlistbox'; import JqxTabs from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxtabs'; class App extends React.PureComponent<{}, {}> { private myTabs = React.createRef(); private usernameInput = React.createRef(); private passwordInput = React.createRef(); private acceptCheckBox = React.createRef(); private products = React.createRef(); private orderContainer = React.createRef(); constructor(props: {}) { super(props); this.acceptCheckBoxChange = this.acceptCheckBoxChange.bind(this); this.productsChange = this.productsChange.bind(this); this.productsUnselect = this.productsUnselect.bind(this); } public componentDidMount() { this.addHandlers(); this.validate(true); this.showHint('Validation hints.', '#hintSection'); } public render() { return (
  • Personal info
  • Shopping basket
  • Review order
Username:
Password:
I accept the terms and conditions
Next
Back Next

Selected products

Back
); } private addHandlers = () => { this.usernameInput.current!.addEventListener('keyup', () => { this.validate(true); }); this.usernameInput.current!.addEventListener('change', () => { this.validate(true); }); this.passwordInput.current!.addEventListener('keyup', () => { this.validate(true); }); const nextButtonClass = document.querySelectorAll('.nextButton'); nextButtonClass.forEach(nextButton => { nextButton.addEventListener('click', (e) => { this.validate(true); const selectedTab = this.myTabs.current!.getOptions('selectedItem'); this.myTabs.current!.select(selectedTab + 1); }); }); const backButtonClass = document.querySelectorAll('.backButton'); backButtonClass.forEach(backButton => { backButton.addEventListener('click', () => { this.validate(true); const selectedTab = this.myTabs.current!.getOptions('selectedItem'); this.myTabs.current!.select(selectedTab - 1); }); }); }; // Checking if any product have been selected private isItemSelected = (array: any) => { let count = array.length; if (count === 0) { return false; } while (count) { count -= 1; if (array[count] !== -1 && typeof array[count] !== 'undefined') { return true; } } return false; }; // Validating all wizard tabs private validate = (notify: boolean) => { if (!this.firstTab(notify)) { this.myTabs.current!.disableAt(1); this.myTabs.current!.disableAt(2); return; } else { this.myTabs.current!.enableAt(1); } if (!this.secondTab(notify)) { this.myTabs.current!.disableAt(2); return; } else { this.myTabs.current!.enableAt(2); } }; // Displaying message to the user private showHint = (message: string, selector: string) => { if (typeof selector === 'undefined') { selector = '.hint'; } if (message === '') { message = 'You can continue.'; } // Check is a class or not if (selector.indexOf('.') === 0) { document.getElementsByClassName(selector.slice(1))[0].innerHTML = '' + message + ''; } else { document.getElementById(selector.slice(1))!.innerHTML = '' + message + ''; } } // Validating the first tab private firstTab = (notify: boolean) => { const username = this.usernameInput.current!.value; const password = this.passwordInput.current!.value; let message = ''; if (username.length < 3) { message += 'You have to enter valid username.
'; } if (password.length < 3) { message += 'You have to enter valid password.
'; } if (!this.acceptCheckBox.current!.getOptions("checked")) { message += 'You have to accept the terms.
'; } if (message !== '') { if (notify) { this.showHint(message, '#hintSection'); } return false; } this.showHint('You can continue.', '#hintSection'); return true; }; // Validating the second tab private secondTab = (notify?: boolean) => { const products = this.products.current!.getOptions("selectedIndexes"); if (!this.isItemSelected(products)) { this.showHint('You have to select at least one item.', '#hintBasket'); return false; } else { this.showHint('You can continue.', '#hintBasket'); } return true; }; // Event handling private acceptCheckBoxChange(event: any): void { this.validate(true); } private productsChange(event: any): void { this.validate(true); const selectedItems = this.products.current!.getOptions('selectedIndexes') let count = selectedItems.length; const parent = this.orderContainer.current!; while (parent.firstChild) { parent.removeChild(parent.firstChild); } while (count) { count--; if (typeof selectedItems[count] !== 'undefined' && selectedItems[count] !== -1) { const currentHtmlContent = parent.innerHTML; parent.innerHTML = currentHtmlContent + '
' + (this.getSource()[selectedItems[count]].html) + '
'; } } } private productsUnselect(event: any): void { this.validate(true); } private getSource = (): any[] => { return [ { html: "
jqxNumberInput
", title: 'jqxNumberInput' }, { html: "
jqxProgressBar
", title: 'jqxProgressBar' }, { html: "
jqxCalendar
", title: 'jqxCalendar' }, { html: "
jqxButton
", title: 'jqxButton' }, { html: "
jqxDropDownList
", title: 'jqxDropDownList' }, { html: "
jqxListBox
", title: 'jqxListBox' }, { html: "
jqxTooltip
", title: 'jqxTooltip' } ]; } } export default App;