DevExtreme v24.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

Custom Text Editor Buttons

Text editors have built-in action buttons that allow users to open a drop-down menu, increase, decrease, or nullify the value, and perform other actions. To add custom action buttons for different scenarios, use the buttons[] array.

The USD/EUR rate is taken from www.wikipedia.org and is relevant on 14 April 2021
Backend API
$(() => { const passwordEditor = $('#password').dxTextBox({ placeholder: 'password', mode: 'password', value: 'password', inputAttr: { 'aria-label': 'Password' }, stylingMode: 'filled', buttons: [{ name: 'password', location: 'after', options: { icon: 'eyeopen', stylingMode: 'text', onClick() { passwordEditor.option('mode', passwordEditor.option('mode') === 'text' ? 'password' : 'text'); }, }, }], }).dxTextBox('instance'); const currencyEditor = $('#multicurrency').dxNumberBox({ value: 14500.55, format: '$ #.##', showClearButton: true, showSpinButtons: true, inputAttr: { 'aria-label': 'Multi Currency' }, buttons: [{ name: 'currency', location: 'after', options: { text: '€', stylingMode: 'text', width: 32, elementAttr: { class: 'currency', }, onClick(e) { if (e.component.option('text') === '$') { e.component.option('text', '€'); currencyEditor.option('format', '$ #.##'); currencyEditor.option('value', currencyEditor.option('value') / 0.836); } else { e.component.option('text', '$'); currencyEditor.option('format', '€ #.##'); currencyEditor.option('value', currencyEditor.option('value') * 0.836); } }, }, }, 'clear', 'spins'], }).dxNumberBox('instance'); const millisecondsInDay = 24 * 60 * 60 * 1000; const dateEditor = $('#advanced-datebox').dxDateBox({ value: new Date().getTime(), stylingMode: 'outlined', inputAttr: { 'aria-label': 'Date' }, buttons: [{ name: 'today', location: 'before', options: { text: 'Today', stylingMode: 'text', onClick() { dateEditor.option('value', new Date().getTime()); }, }, }, { name: 'prevDate', location: 'before', options: { icon: 'spinprev', stylingMode: 'text', onClick() { const currentDate = dateEditor.option('value'); dateEditor.option('value', currentDate - millisecondsInDay); }, }, }, { name: 'nextDate', location: 'after', options: { icon: 'spinnext', stylingMode: 'text', onClick() { const currentDate = dateEditor.option('value'); dateEditor.option('value', currentDate + millisecondsInDay); }, }, }, 'dropDown'], }).dxDateBox('instance'); });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/24.1.4/css/dx.light.css" /> <script src="js/dx.all.js"></script> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container"> <div class="dx-fieldset"> <div class="dx-field"> <div class="dx-field-label">Password TextBox</div> <div class="dx-field-value"> <div id="password"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">Multi-currency NumberBox</div> <div class="dx-field-value"> <div id="multicurrency"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">Advanced DateBox</div> <div class="dx-field-value"> <div id="advanced-datebox"></div> </div> </div> </div> </div> </body> </html>
.dx-fieldset { min-height: 560px; width: 560px; margin: 0 auto; } .currency { min-width: 32px; } .dx-button.currency .dx-button-content { font-size: 120%; padding-left: 5px; padding-right: 5px; }

Each object in the buttons[] array should have the name field—the button's identifier. In addition, specify the button's location relative to the input text field and options of the Button component used as the action button.

The buttons[] array also accepts string values—the names of built-in buttons. Declare them in the order the buttons should have in the component. String and object declarations can be used in the same array.