Field Name (number) changed to text #7

Closed
opened 2016-06-05 17:49:05 +00:00 by mwweb · 2 comments
mwweb commented 2016-06-05 17:49:05 +00:00 (Migrated from github.com)

I encountered an issue that I'm not sure if it was by design or an issue.

When creating a field, if I set the address to something like myfield2, upon compile and install the database shows the field as myfieldtwo. It takes the 2 and converts it to two.

This also happens with default values. If I set default="10" it converts this to "ten" upon compile and install.

It looks like this only happens in fields.

I encountered an issue that I'm not sure if it was by design or an issue. When creating a field, if I set the address to something like myfield2, upon compile and install the database shows the field as myfieldtwo. It takes the 2 and converts it to two. This also happens with default values. If I set default="10" it converts this to "ten" upon compile and install. It looks like this only happens in fields.

Yes you are right it is by design. Since fields are used in so many conventions where numbers don't work well and can cause errors. We chose to just convert all field names to text only.

As far as I know the default value is not changed so if you can give me a link to the code I can take a look. It could be that you are speaking of default values in another way than I am understanding.

So to me default values are in the fields area default="10" will stay 10.

Now if you need to iterate fields and therefore want the numbers there is a way to do this with the same function in the helper class called safeString.

So lets say you have four fields myfield1 to myfield4 that you want to target you can do the following:

$items; // this is the data from the Database
$bucket = array(); // to store values
$fields = range(1,4); // the iterate fields
foreach ($items as $item)
{
    foreach ($fields as $field)
    {
        $fieldName = ComponentHelper::safeString('myfield'.$field);
        $bucket[] = $item->$fieldName;
    }
}

You can in the helper file look at the safeString method to see what it does.

Note that ComponentHelper:: will be the name of your component with Helper added to it.

Hope this helps.

Yes you are right it is by design. Since fields are used in so many conventions where numbers don't work well and can cause errors. We chose to just convert all field **names** to text only. As far as I know the default value is not changed so if you can give me a link to the code I can take a look. It could be that you are speaking of default values in another way than I am understanding. So to me default values are in the fields area `default="10"` will stay 10. Now if you need to iterate fields and therefore want the numbers there is a way to do this with the same function in the helper class called **safeString**. So lets say you have four fields myfield1 to myfield4 that you want to target you can do the following: ``` $items; // this is the data from the Database $bucket = array(); // to store values $fields = range(1,4); // the iterate fields foreach ($items as $item) { foreach ($fields as $field) { $fieldName = ComponentHelper::safeString('myfield'.$field); $bucket[] = $item->$fieldName; } } ``` You can in the helper file look at the safeString method to see what it does. Note that **ComponentHelper::** will be the name of your component with Helper added to it. Hope this helps.

Just a headsup note, if you make the default field in fieldtype translatable then it will change it to a string.

Just a headsup note, if you make the default field in fieldtype translatable then it will change it to a string.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#7
No description provided.