Skip to content

Commit 2154a1f

Browse files
committed
[add] a section on gantt work with modalbox buttons
1 parent ad3c4b9 commit 2154a1f

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

data/desktop/message_boxes.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ gantt.modalbox({
199199
~~~
200200

201201

202-
###Configuring modalbox buttons
202+
###Configuring modalbox buttons {#configuringmodalboxbuttons}
203203

204204
There are two main ways to define the configuration of modalbox buttons:
205205

206-
- a short form:
206+
- a short form:
207207

208208
~~~js
209209
gantt.modalbox({
@@ -325,6 +325,84 @@ var box = gantt.confirm({
325325
gantt.modalbox.hide(box);
326326
~~~
327327

328+
##How Gantt Works with Modalbox Buttons
329+
330+
By default, the names of buttons are set as text. If the name of a button is set as an HTML element (e.g. to make the font bold, or add a material icon),
331+
the result of the callback function on clicking the button will be *null*.
332+
333+
It happens as Gantt watches certain attributes of the clicked element's parent. If there aren't the expected attributes, Gantt will return *null*.
334+
Besides, Gantt wraps all the elements you specify for the buttons into the `<div>` tags.
335+
336+
Thus if you return a string element when a text is clicked, its parent will be an empty `<div>` element and you'll get `null`.
337+
But when a button is clicked outside the text, its parent is an element with all the necessary attributes, so you'll get some more expected result:
338+
339+
- *true/false* for the confirm box
340+
- for the modalbox:
341+
- the number of the element in an array (for the [short form](#configuringmodalboxbuttons))
342+
- the value of the `value` parameter (for the [full form](#configuringmodalboxbuttons))
343+
344+
It means that if you want to set an HTML element as a button name, you need to wrap everything into two div elements that have the `data-result` attribute. For example:
345+
346+
~~~js
347+
gantt.confirm({
348+
ok:`<div data-result="yes"><div data-result="yes"><i>Yes</i></div></div>`,
349+
cancel:`<div data-result="no"><div data-result="no"><i>No</i></div></div>`,
350+
});
351+
352+
gantt.modalbox({
353+
buttons: [
354+
{ label:`<div data-result="yes">
355+
<div data-result="yes"><i>Yes</i></div>
356+
</div>`,
357+
css:"link_save_btn", value:"yes" },
358+
{ label:`<div data-result="no">
359+
<div data-result="no"><i>No</i></div>
360+
</div>`,
361+
css:"link_cancel_btn", value:"no" },
362+
{ label:`<div data-result="cancel">
363+
<div data-result="cancel"><i>Cancel</i></div>
364+
</div>`,
365+
css:"link_cancel_btn", value:"cancel" },
366+
],
367+
});
368+
~~~
369+
370+
If you need to use some other elements for a button, all the parent elements should also have the `data-result` attribute. In the example below
371+
the `<u>` tags are used for the name of the button. So, they have the `data-result` attribute the same as the other two `<div>` parent elements of the button:
372+
373+
~~~js
374+
gantt.confirm({
375+
ok:`<div data-result="yes">
376+
<div data-result="yes"><u data-result="yes"><i>Yes</i></u></div>
377+
</div>`,
378+
cancel:`<div data-result="no">
379+
<div data-result="no"><u data-result="no"><i>No</i></u></div>
380+
</div>`,
381+
});
382+
383+
gantt.modalbox({
384+
buttons: [
385+
{ label:`<div data-result="yes">
386+
<div data-result="yes">
387+
<u data-result="yes"><i>Yes</i></u>
388+
</div>
389+
</div>`,
390+
css:"link_save_btn", value:"yes" },
391+
{ label:`<div data-result="no">
392+
<div data-result="no">
393+
<u data-result="no"><i>No</i></u>
394+
</div>
395+
</div>`,
396+
css:"link_cancel_btn", value:"no" },
397+
{ label:`<div data-result="cancel">
398+
<div data-result="cancel">
399+
<u data-result="cancel"><i>Cancel</i></u>
400+
</div>
401+
</div>`,
402+
css:"link_cancel_btn", value:"cancel" },
403+
],
404+
});
405+
~~~
328406

329407
##Styling
330408

0 commit comments

Comments
 (0)