Coder Social home page Coder Social logo

Comments (10)

milewski avatar milewski commented on August 25, 2024

uhm.. can you do a quickly test,

Instead of using creationRules and updateRules use just rules if it works I think I know what may be wrong and I can issue a quickly fix...

from conditional-container.

milewski avatar milewski commented on August 25, 2024

Hi @nemrutco I just doubled checked.. it does work with creationRules and updateRules did you import use HasConditionalContainer; ?

from conditional-container.

 avatar commented on August 25, 2024

i just tried

 ConditionalContainer::make([
                Text::make(__('Username'), 'username')->rules('required'),
            ])->if('role != 3'),

and it still doesn't work.

Yes i imported use HasConditionalContainer

from conditional-container.

milewski avatar milewski commented on August 25, 2024

Is this how you are using it?

public function fields(Request $request)
{
    return [

        Select::make(__('Role'), 'role')
              ->options([
                  1 => 'A',
                  2 => 'B',
                  3 => 'C',
              ]),

        ConditionalContainer::make([

            Text::make(__('Name'), 'name')
                ->creationRules('required', 'max:255')
                ->updateRules('required', 'max:255'),

        ])->if('role != 3'),

    ];
}

role needs to be an actual field in your model otherwise it wont be able to detect it

If its not.. you can try something like this: #7 (comment)

from conditional-container.

 avatar commented on August 25, 2024
public function fields(Request $request)
    {
        return [
            ID::make()->sortable()
                ->onlyOnForms(),

            BelongsTo::make(__('Role'), 'role')->withMeta([
                'belongsToId' => $this->role->id ?? null
            ]),

            Text::make(__('Name'), 'name')->onlyOnIndex(),

            ConditionalContainer::make([
                Text::make(__('Username'), 'username')
                    ->sortable()
                    ->creationRules('required', 'unique:users,username', 'max:254', 'alpha_dash')
                    ->updateRules('sometimes', 'required', 'unique:users,username,{{resourceId}}', 'max:254', 'alpha_dash'),

                Password::make(__('Password'), 'password')
                    ->onlyOnForms()
                    ->creationRules('required', 'string', 'min:8')
                    ->updateRules('sometimes', 'required', 'string', 'min:8'),
            ])->if('role != 3'),

            Text::make(__('Employee Number'), 'employee_number')
                ->sortable()
                ->rules('required', 'integer'),

            BelongsToMany::make(__('Stores'), 'stores')
                ->searchable(),

            MorphOne::make(__('Card'), 'card'),

            BelongsTo::make(__('Profile'), 'profile', Profile::class)
                ->inline()
                ->rules('required')
                ->hideFromIndex(),

            HasMany::make(__('Sales'), 'sales'),
        ];
    }

from conditional-container.

 avatar commented on August 25, 2024

role is an actual field. And i just tried another field as well.

            ConditionalContainer::make([
                Text::make(__('Employee Number'), 'employee_number')
                    ->sortable()
                    ->rules('required', 'integer'),
            ])->if('role != 3'),

still not working.

Did you mean role has to be a field in model table? Because role is relationship in my case.

from conditional-container.

milewski avatar milewski commented on August 25, 2024

@nemrutco fixed on version v1.1.3, the problem was with the BelongsTo and the != operator, on the way I found it had the same issue with other operators as well >= <= != !== it's now fixed, try again

from conditional-container.

 avatar commented on August 25, 2024

Fixed! Thank you.

from conditional-container.

 avatar commented on August 25, 2024

Another issue related to this:
when password field is nullable, it submits password to db as null and db updates the value to null (db password field is nullable) but when i use without ConditionalContainer, null value does not update db so old password stays. Why does it update db when it is nullable? it should ignore the field.

Password::make(__('Password'), 'password')
                    ->onlyOnForms()
                    ->creationRules('required', 'string', 'min:8')
                    ->updateRules('sometimes', 'nullable', 'string', 'min:8')

from conditional-container.

milewski avatar milewski commented on August 25, 2024

Please open another issue with this otherwise it may get forgotten in here

from conditional-container.

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.