Eugene Starosvetskiy
Eugene Starosvetskiy

Reputation: 141

Is it possible to change text of switch?

That's it. I googled. I didn't find anything.

enter image description here

Upvotes: 0

Views: 372

Answers (2)

Hardik Satasiya
Hardik Satasiya

Reputation: 9715

yes absolutely you need to add additional property for field.

you can find whole reference here : https://octobercms.com/docs/backend/forms#field-switch

my_switch:
    label: Yes/No
    type: switch
    comment: Just Example
    on: myauthor.myplugin::lang.models.mymodel.my_switch.on <- this
    off: myauthor.myplugin::lang.models.mymodel.my_switch.off <- n this

now for in language file refer this : https://octobercms.com/docs/plugin/localization#file-structure

you need to add language string for that. OR you can directly apply it if you don't want it for multi language

my_switch:
    label: Yes/No
    type: switch
    comment: Just Example
    on: Yes <- this
    off: No <- n this

Above example is only for single form field switch.

To make it work whole site wide in back-end, please refer this : https://octobercms.com/docs/plugin/localization#overriding

you need to create new language file

lang/               <=== App localization directory
  en/               <=== Language directory
    backend/        <=== Plugin / Module directory         
        lang.php    <=== Localization override file

and you need to add this language array to override text, lang.php file content

<?php

return [
    'form' => [
        'field_off' => 'Off',
        'field_on' => 'On'
    ]
];

if any doubt please comment.

Upvotes: 1

Zakir hussain
Zakir hussain

Reputation: 631

you just need to pass values for on and off text properties.

suppose you have below field in yaml file.

show_content:
    label: Display content
    type: switch
    on: 'Yes'
    off: 'No'

you can also learn from documentation https://octobercms.com/docs/backend/forms#field-switch

Upvotes: 1

Related Questions