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

tanzania411
tanzania411

I've a course with many lessons. Each lesson has a weekday dropdown. In list view the translated value shows correctly but when I edit the record the dropdown key gets lost. The keyValue in function getDayOptions is correct (as wednesday from my screenshot sample) Any ideas to get this working? Here some code:

fields.yaml of Models/lesson:

 fields:
    day:
        label: habinho.school::lang.lesson.day
        span: left
        type: dropdown

functions in Models/Lesson.php:

public function getDayOptions($keyValue = null)
{
    $keyValue = $this->getAttributeFromArray('day');
    $options[''] = e(trans('habinho.school::lang.lesson.day_placeholder'));
    $options['monday'] = e(trans('habinho.school::lang.lesson.monday'));
    $options['tuesday'] = e(trans('habinho.school::lang.lesson.tuesday'));
    $options['wednesday'] = e(trans('habinho.school::lang.lesson.wednesday'));
    $options['thursday'] = e(trans('habinho.school::lang.lesson.thursday'));
    $options['friday'] = e(trans('habinho.school::lang.lesson.friday'));
    $options['saturday'] = e(trans('habinho.school::lang.lesson.saturday'));
    $options['sunday'] = e(trans('habinho.school::lang.lesson.sunday'));

    return $options;
}

public function getDayAttribute($value)
{
    return e(trans('habinho.school::lang.lesson.' . $value));
}

List View Edit View

Last updated

tanzania411
tanzania411

With this workaround it works: I made key and value of the dropdown both with the translated text.

public function getDayOptions($keyValue = null)
{
    $keyValue = $this->getAttributeFromArray('day');
    $options[''] = e(trans('habinho.school::lang.lesson.day_placeholder'));
    $options[e(trans('habinho.school::lang.lesson.monday'))] = e(trans('habinho.school::lang.lesson.monday'));
    $options[e(trans('habinho.school::lang.lesson.tuesday'))] = e(trans('habinho.school::lang.lesson.tuesday'));
    $options[e(trans('habinho.school::lang.lesson.wednesday'))] = e(trans('habinho.school::lang.lesson.wednesday'));
    $options[e(trans('habinho.school::lang.lesson.thursday'))] = e(trans('habinho.school::lang.lesson.thursday'));
    $options[e(trans('habinho.school::lang.lesson.friday'))] = e(trans('habinho.school::lang.lesson.friday'));
    $options[e(trans('habinho.school::lang.lesson.saturday'))] = e(trans('habinho.school::lang.lesson.saturday'));
    $options[e(trans('habinho.school::lang.lesson.sunday'))] = e(trans('habinho.school::lang.lesson.sunday'));

    return $options;
}

public function getDayAttribute($value)
{
    return $value;
}

Last updated

1-2 of 2

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