This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

VektarDesign
VektarDesign

I have been really struggling with this as there is very little information about checkboxlist so please, any help would be greatly appreciated!!

I would like it so that when one or more of the options in my checkboxlist has been ticked, the value of said option will then update the amount field.

I'm sort of cheating as I'm using the key value to be the price of the field which I would then like to update the amount field with.

This already works perfectly with the dropdown fields and this does calculate the amount field depending on what has been selected.

As I've had to make the checkboxlist jasonable, the way in which this returns the value is different.

Jobs model:

type_website:
    label: Website Package
    span: right
    type: dropdown
    placeholder: '-- Select Website Package --'
    trigger:
        action: show
        condition: value[1]
        field: type
type_add_pages:
    label: 'Additional Pages'
    span: right
    type: dropdown
    trigger:
        action: show
        condition: value[1]
        field: type
type_addons_get:
    label: 'Addons'
    span: right
    type: checkboxlist
    trigger:
        action: show
        condition: value[1]
        field: type
amount:
   label: 'Total Amount'
   span: left
   type: text
   readOnly: true
   dependsOn:
      - type_add_pages
      - type_website
      - type_addons_get

Jobs.php

protected $jsonable = [
    'type_addons_get'
];

public function getTypeAddonsGetOptions()
{
    return [
        '30' => 'Blog',
        '50' => 'Editable Website'
    ];
}

// Get the value for the amounts field 
public function filterFields($fields, $context = null)
{
    $typePages = $this->attributes['type_add_pages'];
    $typeWebsite = $this->attributes['type_website'];
    $typeAddons = $this->attributes['type_addons_get'];

    return $fields->amount->value = $typeAddons + $typePages + $typeWebsite;

}

As a test, if I just return the following in Jobs.php:

return $fields->amount->value = $typeAddons;

I then get the following result: https://www.dropbox.com/s/szegcgbnzltrymb/img-1.png?dl=0 https://www.dropbox.com/s/7blbqdiykquhwcf/img-2.png?dl=0

Any help would be extremely helpful, thanks in advance!

Last updated

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.