I'm trying to define a markdown link button with the next way

js:
var selection = E.getSelection();
var match = selection.match(/\[([^\]]*)\]\(([^\)]*)\)/) || selection.match(/(.*)\s((?:http|https|ftp|ftps):\/\/\S*)/) || selection.match(/(.*)()/) || ['', '', ''];
var fields =   [
  { name: 'url', title: 'URL', required: true, value: match[2] || '' },
  { name: 'text', title: 'Text', required: true, value: value = match[1] || '' }
];
function submitHandler(tag, form, E) {
  E.replaceSelection('[' + tag.attributes.text + '](' + tag.attributes.url + ')');
};
E.tagDialog('custom_markdown_link', fields, {title: 'Insert link', submit: submitHandler});

So the form values are formed by the selection.
It works correctly for the firls button click.
But when the button is clicked the second time the dialog values are the same as for the first time even if the selection was changed.

The workaround is adding the following two lines:

document.getElementById('bue-field-1').value = match[2] || '';
document.getElementById('bue-field-2').value = match[1] || '';

Comments

chuvilin created an issue. See original summary.

  • ufku committed d952bd2 on 8.x-1.x
    Issue #2893709: Fixed field values not being updated on subsequent calls...
ufku’s picture

Status: Active » Fixed

Fixed in dev branch. Thanks for reporting.

FYI, you can access the form elements by their name:

js:
var selection = E.getSelection();
var match = selection.match(/\[([^\]]*)\]\(([^\)]*)\)/) || selection.match(/(.*)\s((?:http|https|ftp|ftps):\/\/\S*)/) || selection.match(/(.*)()/) || ['', '', ''];
var fields =   [
  { name: 'url', title: 'URL', required: true },
  { name: 'text', title: 'Text', required: true }
];
function submitHandler(tag, form, E) {
  E.replaceSelection('[' + tag.attributes.text + '](' + tag.attributes.url + ')');
};
var dialog = E.tagDialog('custom_markdown_link', fields, {title: 'Insert link', submit: submitHandler});
var elements = dialog.getForm().elements;
elements.url.value = match[2] || '';
elements.text.value = match[1] || '';
ufku’s picture

Version: 8.x-1.0 » 8.x-1.x-dev

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.