Jump to content

I can force unigui controls to sincronize content at server side when content is setted at client side?


ldb68

Recommended Posts

I can force unigui controls to sincronize content at server side when content is setted at client side?

I think is a common problem with uniHtmlFrame and javascript.

If I call a js function to update a unigui control accessing to the content with unigui property give a old value.

In may case I get the content from a tinymce editor via js and copy it to a unimemo:

UniSession.AddJS('MainForm.UniMemo1.setValue(tinyMCE.get("edt1").getContent());');

The memo conntain the text from frame.

If I try to read  the  UniMemo1.text conntent I get the old value (before the js call).

 

Se here for a sample


Link to comment
Share on other sites

Javascript will never actualize the server,thats why

i try to use Delphi all the time.

For me the only reason to use JavaScript is if the component still don´t

do what you want,or for things like local storage .

At least don´t base your logic in the state of the components that you change by using

client side code,the problem is when someone else is going to change your code.

And as far as I know it is not possible to force this sincronization also.

Link to comment
Share on other sites

I can force unigui controls to sincronize content at server side when content is setted at client side?

 

Hi,

 

Fast solution and it can be optimized.

 

Try this:

tinyMCE.init({
    /*selector: '#edt1', */
    plugins: [
        'advlist autolink lists link image charmap print preview anchor',
        'searchreplace visualblocks code fullscreen',
        'insertdatetime media table contextmenu paste code'
    ],
    toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
    content_css: [
        '//fast.fonts.net/cssapi/e6dc9b99-64fe-4292-ad98-6974f93cd2a2.css',
        '//www.tinymce.com/css/codepen.min.css'
    ],
    mode: "exact",
    elements: "edt1",
    setup: function(ed) {
        ed.on('keyup', function(e) {
            MainForm.UniMemo1.setValue(ed.getContent());
        });
        ed.on('change', function(e) {
            MainForm.UniMemo1.setValue(ed.getContent());
        });
    }
});

Best regards.

Link to comment
Share on other sites

Javascript will never actualize the server,thats why

i try to use Delphi all the time.

For me the only reason to use JavaScript is if the component still don´t

do what you want,or for things like local storage .

At least don´t base your logic in the state of the components that you change by using

client side code,the problem is when someone else is going to change your code.

And as far as I know it is not possible to force this sincronization also.

 

Yes.

In my case I'm using the tinymce editor (more advanced of unihtmleditor).

To set and get the content we need JS at client side.

Sincronization can be done by ajaxRequest (event to server side) but is non a "linear" solution.

Link to comment
Share on other sites

Hi,

 

Fast solution and it can be optimized.

 

Try this:

tinyMCE.init({
    /*selector: '#edt1', */
    plugins: [
        'advlist autolink lists link image charmap print preview anchor',
        'searchreplace visualblocks code fullscreen',
        'insertdatetime media table contextmenu paste code'
    ],
    toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
    content_css: [
        '//fast.fonts.net/cssapi/e6dc9b99-64fe-4292-ad98-6974f93cd2a2.css',
        '//www.tinymce.com/css/codepen.min.css'
    ],
    mode: "exact",
    elements: "edt1",
    setup: function(ed) {
        ed.on('keyup', function(e) {
            MainForm.UniMemo1.setValue(ed.getContent());
        });
        ed.on('change', function(e) {
            MainForm.UniMemo1.setValue(ed.getContent());
        });
    }
});

Best regards.

 

Thanks it works.

For small text can be a solution.

For large text I think there is too much overhead.

 

I tried to add a new funtion in the script to be called from main but I can't get to works

 

AferScript

.....

function GetHtml() {

  MainForm.UniMemo1.setValue(tinyMCE.get('edt1').getContent());  

  return ""  

}

 

 

From delphi code I have error (GetHtml() not defined ...)

 UniSession.AddJS('MainForm.UniMemo1.setValue(GetHtml())');

Link to comment
Share on other sites

Hi,

 

OK, for now can you try this ?!:

 

1. Use setRawValue instead of setValue

tinyMCE.init({
    /*selector: '#edt1', */
    plugins: [
        'advlist autolink lists link image charmap print preview anchor',
        'searchreplace visualblocks code fullscreen',
        'insertdatetime media table contextmenu paste code'
    ],
    toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
    content_css: [
        '//fast.fonts.net/cssapi/e6dc9b99-64fe-4292-ad98-6974f93cd2a2.css',
        '//www.tinymce.com/css/codepen.min.css'
    ],
    mode: "exact",
    elements: "edt1",
    setup: function(ed) {
        ed.on('keyup', function(e) {
            MainForm.UniMemo1.setRawValue(ed.getContent());
        });
        ed.on('change', function(e) {
            MainForm.UniMemo1.setRawValue(ed.getContent());
        });
    }
});

2.

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  ShowMessage(UniMemo1.Text);
end;

Best regards.

Link to comment
Share on other sites

  • 1 year later...
I'm doing a similar procedure, I get an HTML via JavaScrit, it visually appears on the screen in uniMemo, but on the server side it says Memo is empty.

 

I'm using uniGUI Extjs 6.5, has anything changed?

 

how to do that on the server side I can capture the contents of Memo

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...