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.
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.
The USD/EUR rate is taken from www.wikipedia.org and is relevant on 14 April 2021
Feel free to share demo-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Backend API
<div class="dx-fieldset">
<div class="dx-field">
<div class="dx-field-label">Password TextBox</div>
<div class="dx-field-value">
@(Html.DevExtreme().TextBox()
.ID("password")
.Value("password")
.InputAttr("aria-label", "Password")
.Placeholder("password")
.Mode(TextBoxMode.Password)
.StylingMode(EditorStylingMode.Filled)
.Buttons(buttons => {
buttons.Add()
.Name("password")
.Location(TextEditorButtonLocation.After)
.Widget(w => w.Button()
.Type(ButtonType.Default)
.Icon(Url.Content("~/Content/Images/icons/eye.png"))
.OnClick("changePasswordMode"));
})
)
</div>
</div>
<div class="dx-field">
<div class="dx-field-label">Multi-currency NumberBox</div>
<div class="dx-field-value">
@(Html.DevExtreme().NumberBox()
.ID("multicurrency")
.Value(14500.55)
.Format("$ #.##")
.ShowClearButton(true)
.ShowSpinButtons(true)
.InputAttr("aria-label", "Multi Currency")
.Buttons(buttons => {
buttons.Add()
.Name("currency")
.Location(TextEditorButtonLocation.After)
.Widget(w => w.Button()
.Text("€")
.StylingMode(ButtonStylingMode.Text)
.Width(32)
.ElementAttr("class", "currency")
.OnClick("changeCurrency"));
buttons.Add()
.Name("clear");
buttons.Add()
.Name("spins");
})
)
</div>
</div>
<div class="dx-field">
<div class="dx-field-label">Advanced DateBox</div>
<div class="dx-field-value">
@(Html.DevExtreme().DateBox()
.ID("advanced-datebox")
.InputAttr("aria-label", "Date")
.Value(new JS("new Date().getTime()"))
.StylingMode(EditorStylingMode.Outlined)
.OnInitialized("dateOnInitialized")
.Buttons(buttons => {
buttons.Add()
.Name("today")
.Location(TextEditorButtonLocation.Before)
.Widget(w => w.Button()
.Text("Today")
.OnClick("today"));
buttons.Add()
.Name("prevDate")
.Location(TextEditorButtonLocation.Before)
.Widget(w => w.Button()
.Icon("spinprev")
.StylingMode(ButtonStylingMode.Text)
.OnClick("prevDate"));
buttons.Add()
.Name("nextDate")
.Location(TextEditorButtonLocation.After)
.Widget(w => w.Button()
.Icon("spinnext")
.StylingMode(ButtonStylingMode.Text)
.OnClick("nextDate"));
buttons.Add()
.Name("dropDown");
})
)
</div>
</div>
</div>
<script>
var millisecondsInDay = 24 * 60 * 60 * 1000;
function changePasswordMode() {
var passwordEditor = $("#password").dxTextBox("instance");
passwordEditor.option("mode", passwordEditor.option("mode") === "text" ? "password" : "text");
}
function changeCurrency(e) {
var currencyEditor = $("#multicurrency").dxNumberBox("instance");
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);
}
}
var dateEditor;
function dateOnInitialized(e) {
dateEditor = e.component;
}
function today() {
dateEditor.option("value", new Date().getTime());
}
function prevDate() {
dateEditor.option("value", dateEditor.option("value") - millisecondsInDay);
}
function nextDate() {
dateEditor.option("value", dateEditor.option("value") + millisecondsInDay);
}
</script>
using DevExtreme.AspNet.Data;
using DevExtreme.AspNet.Mvc;
using DevExtreme.MVC.Demos.Models;
using DevExtreme.MVC.Demos.Models.SampleData;
using DevExtreme.MVC.Demos.ViewModels;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DevExtreme.MVC.Demos.Models.DataGrid;
namespace DevExtreme.MVC.Demos.Controllers {
public class CommonController : Controller {
public ActionResult CustomTextEditorButtons() {
return View();
}
}
}
.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;
}