Changing Button Text
Changing Button Text
Hi Allan,
A double click on a cell in datatable A invokes editor/datatable B.
editor/Datatable B has a customised 'create' form with modified title & button text. The customised 'create' form is accessed in one of 2 ways:
- via the classic datatable 'create' button
- via an editor.create().open() call
In my test the option 1 uses i18n to populate the create form. However, option 2 does not seem to use i18n. This caused me some confusion.
The solution:
Using option 2, I can customise the 'create' form by using formOptions in the editor configuration OR by setting options on the fly inside editor.create({options}).open(). Setting options on the fly is not ideal in my use case, so I used formOptions with the resulting code outtake from editor settings:
table: "#adminDt",
i18n: {
create: { //<--- CUSTOMISE CREATE FORM ACCESSED VIA DATATABLE BTN
button: 'Add template', // datatable button text
title: 'Add template to page', // Form title
submit: 'Submit' // form submit text
}
},
formOptions: {
main: { // <--- CUSTOMISE CREATE FORM ACCESSED VIA editor.create().open()
title: 'Add template to page', // DUPLICATION
buttons: [
'Submit' // DUPLICATION
]
}
}
The solution above works but it seems I'm DUPLICATING on the settings. Is this intended behaviour?
The ideal behaviour might be to use the customisation text for ALL 'create' forms in i18n UNLESS there is an option overridden elsewhere?
I look forward to hearing back.
Steve
PS:
Potential Correction in Docs:
https://editor.datatables.net/reference/button/create
Example 3 on this page to use legacy fn / label when it might be better to use action / text according to section 'Legacy' in the page below
This question has an accepted answers - jump to answer
Answers
In this case, since you are triggering the create action via both the API and the predefined
create
button then yes this is expected.The
formOptions
are used as the default, but the predefined buttons have their own options already specified (which in turn are overridden by thei18n
option.That is counterintuative thinking about it now...! But for the moment it is expected I'm afraid.
Allan