4

I'm creating a new lightswitch field and adding it to an entry type in a section which already has dozens of entries. I want the lightswitch to be default set to 'on'.

When I save the entry type with the lightswitch field added to a tab, then inspect an entry in that section, the new lightswitch field is set to 'off'. Is this a bug?

7

For entries previously created, the lightswitch field will not be on even if you specified that as a field option. However, new entries should respect that field setting.

Are new entries not honoring your field settings?

|improve this answer|||||
  • I see, I did not expect that behaviour, you are correct in that is what I am experiencing. Presumably I'd have to write a plugin to re-save entries with the 'on' value set. – Adam Menczykowski Feb 21 '17 at 20:52
  • @AdamMenczykowski If you're comfortable with SQL, you could update the value of light switch field in the content table for entry elements in the desired section. Not super simple but should be quick and painless if you can write the SQL with a couple criteria in the where clause. – Selvin Ortiz Feb 21 '17 at 21:57
  • Could anyone provide example code on how to write SQL query code to enable all lightswitches on existing entries please? – Adam Menczykowski Jan 4 '18 at 12:04
  • I too would like example sql code – CreateSean Aug 22 '18 at 16:34
  • Is there no way of selecting all entries in a structure and re-saving all at once? – mateostabio Jun 5 '19 at 15:25
1

This is the mySQL query I have used to update a lightswitch field in the database.

UPDATE `table` SET `field_name` = replace(field_name,'original content', 'updated content')

for example:

UPDATE `craft_content` SET `field_imageLightbox` = replace(field_imageLightbox,'0', '1')
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.