GithubHelp home page GithubHelp logo

issue with saveFoo about tall-forms HOT 8 CLOSED

goldienz avatar goldienz commented on August 22, 2024
issue with saveFoo

from tall-forms.

Comments (8)

goldienz avatar goldienz commented on August 22, 2024

Apologies for the horrific markdown!

from tall-forms.

tanthammar avatar tanthammar commented on August 22, 2024

I am not är the office right now. A small note from my phone:
Try $selected_channels = data_get($this->relationship_data, 'channel_ids');
dd($selected_channels);

Works?

Don't remember, on the fly, if it's relationhip_data or relationships_data.

Please try both and let me know :)

(Very hard to reply w the phone keyboard)

from tall-forms.

tanthammar avatar tanthammar commented on August 22, 2024

Back at the office again.
The relation() save method worked differently in v3... disregard my previous comment about $relationship_data.
I released a fix 4.1.3.

Upgrade and this should work as documented:

public function saveChannelIds($validated_value)
{
    //get the options that the user selected via the field name
    $selected_channels = $validated_value;
    dd($selected_channels);
}

Please let me know if there are any other errors, or please close this issue :).

Thank you for reporting.
//Tina

from tall-forms.

goldienz avatar goldienz commented on August 22, 2024

Thanks for the fix, however the $this->model is returning as bool true, and not an instance. Is this related, or could it be something else that ive done (my code is still as above - didnt want to touch anything else just in case.)

from tall-forms.

goldienz avatar goldienz commented on August 22, 2024
public function saveChannelIds($validated_value)
    {
        $selected_channels = $validated_value;
        dd($this->model);
        if (blank($selected_channels)) {
            $this->model->channels()->detach(); //detach all existing relations
        } else {
            $allowed_to_sync = filled($selected_channels) ? array_intersect($selected_channels, array_values($this->channels)) : [];
            if (filled($allowed_to_sync)) $this->model->channels()->sync($selected_channels);
        }
    }

from tall-forms.

goldienz avatar goldienz commented on August 22, 2024

Have just been tinkering and it appears that the $this->model changes state somewhere in the TallForm.php success() function.

Did a dump of $this->model before and after this line:
filled($this->model) && $this->model->exists ? $this->onUpdateModel($model_fields_data) : $this->onCreateModel($model_fields_data);

Before: return instance of the model as expected
After: returns true

Will keep looking as to what is making that change, but hopefully thats helpful.

from tall-forms.

goldienz avatar goldienz commented on August 22, 2024

Please ignore the above 'error'. It was due to lazy copy & paste!

In your example here you have a method that overrides the default onUpdateModel function.

// Optional method, this already exists in the TallForm trait
    public function onUpdateModel($validated_data)
    {
        $this->model = $this->model->update($validated_data);
    }

It CLEARLY states it is optional HAHA

It behaves differently to the onUpdateModel function in the TallForm.php file

    public function success($model_fields_data)
    {
        // you have to add the methods to your component
        filled($this->model) && $this->model->exists ? $this->onUpdateModel($model_fields_data) : $this->onCreateModel($model_fields_data);

    }

The true response was coming from the one in my model returning a true to the model being saved, and then setting that as the new value for $this->model.

I will close this now as you've solved the initial thing for me, the second part was clearly just a user error!

Thanks!

from tall-forms.

tanthammar avatar tanthammar commented on August 22, 2024

@goldienz
Good catch,
I updated the stubs files and documentation to avoid confusion.
v4.1.4, has the correct syntax in the stub files.

Thank you for telling me.

from tall-forms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.