How to use indepedent form whit Editor?

How to use indepedent form whit Editor?

joseoliveiraborlasjoseoliveiraborlas Posts: 80Questions: 8Answers: 3

Hello,
I have a form with inputs, and I want to use it to send and edit date with the editor. But I didn't want to use the inputs and model he creates, I wanted to use basicly an independent form.

I have the following formid "formcoiso"
I collect the information in the submit: $ ('#formcoiso'). submit (function (event) {...
And I get the input data with: var form_data = $ (this) .serializearray ();

But from here I can't do anything else. The "editor.create ({" it seems to do nothing, just open the modal. Does anyone have any practical examples to understand the operation?

Code Example:

    <form class="form-horizontal" id="formcoiso">
    <input type="text" class="form-control" id="marca" name="marca" />
    ... 
    <thead>
        <tr>
            <th>Marca</th>
    ...
    var editor = new $.fn.dataTable.Editor( {
        ajax: 'ills.php?i=<?php echo $_GET["id"]; ?>',
        table: '#ells',
        fields: [
            {"label": "Marca","name": "marca", },
    ...
    $('#formcoiso').submit(function(event) {
        event.preventDefault();
        var form_data = $(this).serializeArray();
        editor.create({
            ajax: 'ills.php?i=<?php echo $_GET["id"]; ?>',
            table: 'ells',
            fields: [
                {label: 'Marca', name: 'marca'},
    ...
            data: form_data,
                success: function() {
                  table.ajax.reload(); //table exist already
                }

This question has an accepted answers - jump to answer

Answers

  • joseoliveiraborlasjoseoliveiraborlas Posts: 80Questions: 8Answers: 3

    Anyone? :neutral:

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    Maybe you want Standalone editing. See these examples.

    Kevin

  • allanallan Posts: 63,520Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Anyone?

    You might need to wait a little bit longer than 4 hours at the weekend I'm afraid :). I normally work UK office hours.

    Regarding your question - Kevin is right standalone editing might be an option, but if I'm understanding your question correctly, you want to use input elements that you create and then pass the data through Editor? You could use the Editor API, such as create() and val() to set values, before submitting.

    Regards,
    Allan

  • joseoliveiraborlasjoseoliveiraborlas Posts: 80Questions: 8Answers: 3
    edited February 2023

    Thank You @kthorngren and @Allan,

    tipo = $("tipo").val;
    editor
    .create(false)
    .val( 'tipo', tipo )
    ...
    .submit();

    but the parameter ".create(false)" doesn't work correctly? The modal is opened and closed right after. Any way to avoid it?

    And by the way, in the table I already have an "Edit" button, how do you do the opposite: that is, select a row, press the edit button and autocomplete the inputs to edit and .submit again whit the button of the form?

  • allanallan Posts: 63,520Questions: 1Answers: 10,473 Site admin

    What version of Editor are you using? And can you link to a page showing the issue please?

    Allan

  • joseoliveiraborlasjoseoliveiraborlas Posts: 80Questions: 8Answers: 3

    Thank you for your help. But I ended up seeing the potential in the Editor forms, and was able to modify them as intended. Thanks.

Sign In or Register to comment.