Jump to content

Can't change field to certain types


adrian
 Share

Recommended Posts

Just wondering if I am missing something, but is there a reason I can't change a field type that is set to 'text' to anything numeric?

It was originally set to float, but due to some rounding issues I couldn't resolve, I thought I'd try text. Now the option to change back is no longer available.

Thanks

Link to comment
Share on other sites

Good point, but I wonder whether this behaviour could be overridden during development, perhaps by enabling any field type changes when: $config->advanced = true;

That's a good idea. Though I'd still be nervous about it. :) Something to think about adding though...

One way you can override things on your own is to edit the Fieldtype module file that you want to convert from. So if you've got a float that you want to convert to a string, edit /wire/modules/Fieldtype/FieldtypeFloat.module and add the following function to it (temporarily): 

/**
 * Return Fieldtypes that are compatible with this one (i.e. ones the user may change the type to)
 *
 * @param Field $field Just in case it's needed
 * @return Fieldtypes|null
 *
 */
public function ___getCompatibleFieldtypes(Field $field) {
  $fieldtypes = new Fieldtypes();
  $fieldtypes->add($this->fieldtypes->get('FieldtypeText')); 
  return $fieldtypes;
}

If the Fieldtype you are editing already has that function, that you could just modify it according to what you need.

  • Like 3
Link to comment
Share on other sites

Thanks for that tip Ryan - that might come in handy for sure. At the moment I end up having to delete the field and re-create it, which of course means deleting it from any templates that use it (otherwise I get: This field may not be deleted because it is in use by one or more templates.), re-create the field with the new type, and add it back to the template again. I completely understand the data loss issues and in reality I really shouldn't have to change between numeric and text field types very often during the design phase (if I have my act together from the start), so I guess it's no big deal.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...