jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.42k stars 714 forks source link

select2 implementation #795

Open Pdroh opened 6 months ago

Pdroh commented 6 months ago

hi @jerosoler! Firstly, I would like to thank you for making such a powerful component available to the community openly. and my question is related to the use of other components to, for example, help with visual identity and make it more educational for the user. I'm trying to use select2, but every time I load a new select on a node it doesn't allow updating the DATA object within the node's json. Could you guide me where I could check the object update? I apologize for my bad English lol.

Captura de Tela 2023-12-11 às 19 33 01

jerosoler commented 6 months ago

Are you using the df variables?

Maybe the select2 library does not update the data. Yes that's how it is. You can force the update with the method: updateNodeDataFromId

View in: https://github.com/jerosoler/Drawflow#methods

Example df-variables: https://github.com/jerosoler/Drawflow/issues/226

Pdroh commented 6 months ago

@jerosoler, thank you very much for the quick support! But I believe it didn't work in my case because when I use it this way it modifies the entire Data object. I found another way to solve it by setting a global variable with the Node id and in the change of select2 it only changes the direct value in the object so as not to change the other values of other fields that are in the data object as well. See the example below:

`
Exemple:

    var idNodeSelected = 0;
    editor.on('nodeSelected', function(id) {
       idNodeSelected = id;
    })

    $('.select-header').select2({
        theme: 'bootstrap'
    }).on("change", function (e) {
        editor.drawflow.drawflow.Home.data[idNodeSelected].data.pergunta = $(this).val()
    });

`