Saving non- translatable fields.



  • I have added a mix of translatable and non-translatable fields into my form

    Example Locations:
    Name (trans)
    Description (trans)
    Lat (non-trans)
    Long (non-trans)

    Table Schema:


    location__locations
    id
    lat
    long



    location__locations_translations
    id
    name
    desc
    location_id


    Entity/Location.php

    protected $table = 'location__locations';
    public $translatedAttributes = ['name', 'desc'];
    protected $fillable = ['name', 'desc', 'lat', 'long'];
    

    View/Partials/edit-fields.blade.php

            <?php $old = $location->hasTranslation($lang) ? $location->translate($lang)->name : '' ?>
            {!! Form::text("{$lang}[name]", old("{$lang}.name", $old), []) !!}
    
            {!! Form::text("lat", old("lat", $location->lat), []) !!}
    

    You can see that I don't name the "lat" input with the locale[field_name] convention. It loads the data in fine but doesn't update fields outside the locale array that is submitted.

    I can add in my own logic in the controller to do this but I am wondering .... Am I missing something that would get the built in save method to save fields not in the locale array?


  • Global Moderator

    @Demaestro

    There should be no custom functionality required for this.
    Are you working on v1 or v2 of asgard? Can you post your Entity/LocationTranslations?
    What's in your create-fields.blade.php?

    Thanks.



  • Hi Armababy.

    Thanks for the reply. Just looking at the code you asked for and I see maybe I missed a config. But this is what I have. I think I a using version 1 but not sure where to check. This is my relevant composer.json code that has me thinking I am version 1.

      "require": {
        "laravel/framework": "~5.1",
        "pingpong/modules": "dev-feature/5.1",
        "cartalyst/sentinel": "~2.0",
        "asgardcms/core-module": "~1.0",
        "asgardcms/dashboard-module": "~1.0",
        "asgardcms/user-module": "~1.0",
        "asgardcms/setting-module": "~1.0",
        "asgardcms/media-module": "~1.0",
        "asgardcms/page-module": "~1.0",
        "asgardcms/menu-module": "~1.0",
        "asgardcms/workshop-module": "~1.0",
        "asgardcms/translation-module": "^1.14",
        "asgardcms/flatly-theme": "~1.0",
        "asgardcms/adminlte-theme": "~1.0"
      },
    
    <?php namespace Modules\Location\Entities;
    
    use Illuminate\Database\Eloquent\Model;
    class LocationTranslation extends Model
    {
        public $timestamps = false;
        protected $fillable = [];
        protected $table = 'location__location_translations';
    }
    
    <?php namespace Modules\Location\Entities;
    
    use Dimsav\Translatable\Translatable;
    use Illuminate\Database\Eloquent\Model;
    
    class Location extends Model
    {
        use Translatable;
    
        protected $table = 'location__locations';
        public $translatedAttributes = ['name', 'desc'];
        protected $fillable = ['name', 'desc', 'lat', 'long'];
    
        public function team_members() {
        	return $this->belongToMany('LocationMember');
        }
    }
    


  • @armababy

    Sorry I just found the version.
    1.14.1



  • An additional note:
    The create method isn't working either. The data was seeded through migrations.



  • So I found the root of the problem but not sure the cause or the solution.

    I dumped the request data on form post, and the data is being sent with the old value even though I updated the value in the form.

    If I inspect the text input element after typing a new value in, the old value is still shows in the value attribute of the text input. Even though the new value is shown in the textbox.

    Even on create, the values are empty for the non-translated fields. Did I mess something up with how I am creating the inputs?

    Any idea what I could have done to cause the value to not be updated in a text box?

    Name and Slug post the values I give them. lat and long will only post the values the form loads with.

    partials/edit-fields.blade.php

    <div class="box-body">
        <div class="box-body">
            <div class='form-group{{ $errors->has("{$lang}.name") ? ' has-error' : '' }}'>
                {!! Form::label("{$lang}[name]", trans('location::locations.form.name')) !!}
                <?php $old = $location->hasTranslation($lang) ? $location->translate($lang)->name : '' ?>
                {!! Form::text("{$lang}[name]", old("{$lang}.name", $old), ['class' => 'form-control', 'data-slug' => 'source', 'placeholder' => trans('location::locations.form.name')]) !!}
                {!! $errors->first("{$lang}.name", '<span class="help-block">:message</span>') !!}
            </div>
            <div class='form-group{{ $errors->has("slug") ? ' has-error' : '' }}'>
                {!! Form::label("{$lang}[slug]", trans('teammember::teammembers.form.slug')) !!}
                <?php $old = $location->hasTranslation($lang) ? $location->translate($lang)->slug : '' ?>
                {!! Form::text("{$lang}[slug]", old("{$lang}.slug", $old), ['class' => 'form-control slug', 'data-slug' => 'target', 'placeholder' => trans('teammember::teammembers.form.slug')]) !!}
                {!! $errors->first("{$lang}.slug", '<span class="help-block">:message</span>') !!}
            </div>
            <div class='form-group{{ $errors->has("lat") ? ' has-error' : '' }}'>
                {!! Form::label("lat", trans('location::locations.form.lat')) !!}
                {!! Form::text("lat", old("lat", $location->lat), ['class' => 'form-control', 'placeholder' => trans('location::locations.form.lat')]) !!}
                {!! $errors->first("lat", '<span class="help-block">:message</span>') !!}
            </div>
            <div class='form-group{{ $errors->has("long") ? ' has-error' : '' }}'>
                {!! Form::label("long", trans('location::locations.form.long')) !!}
                {!! Form::text("long", old("long", $location->long), ['class' => 'form-control', 'placeholder' => trans('location::locations.form.long')]) !!}
                {!! $errors->first("long", '<span class="help-block">:message</span>') !!}
            </div>
        </div>
    </div>
    

    partials/create-fields.blade.php

    <div class="box-body">
        <div class="box-body">
            <div class='form-group{{ $errors->has("{$lang}.name") ? ' has-error' : '' }}'>
                {!! Form::label("{$lang}[name]", trans('teammember::teammembers.form.name')) !!}
                {!! Form::text("{$lang}[name]", old("{$lang}.name"), ['class' => 'form-control', 'data-slug' => 'source', 'placeholder' => trans('teammember::teammembers.form.name')]) !!}
                {!! $errors->first("{$lang}.name", '<span class="help-block">:message</span>') !!}
            </div>
            <div class='form-group{{ $errors->has("slug") ? ' has-error' : '' }}'>
                {!! Form::label("{$lang}[slug]", trans('teammember::teammembers.form.slug')) !!}
                {!! Form::text("{$lang}[slug]", old("{$lang}.slug"), ['class' => 'form-control slug', 'data-slug' => 'target', 'placeholder' => trans('teammember::teammembers.form.slug')]) !!}
                {!! $errors->first("{$lang}.slug", '<span class="help-block">:message</span>') !!}
            </div>
            <div class='{{ $errors->has("{$lang}.lat") ? ' has-error' : '' }}'>
                {!! Form::label("lat", trans('teammember::teammembers.form.lat')) !!}
                {!! Form::text("lat", old("lat"), ['class' => 'form-control', 'placeholder' => trans('teammember::teammembers.form.lat')]) !!}
                {!! $errors->first("lat", '<span class="help-block">:message</span>') !!}
            </div>
            <div class='{{ $errors->has("{$lang}.long") ? ' has-error' : '' }}'>
                {!! Form::label("long", trans('teammember::teammembers.form.long')) !!}
                {!! Form::text("long", old("long"), ['class' => 'form-control', 'placeholder' => trans('teammember::teammembers.form.long')]) !!}
                {!! $errors->first("long", '<span class="help-block">:message</span>') !!}
            </div>
        </div>
    </div>
    


  • So I figured out my issue in case anyone else is having it.

    You can not put non translatable fields in the partial/xxxx-fields/.blade.php files. If you remove the lang naming convention the input is drawn twice, once for each tab. Since the input has the same name in each tab it only submits the value for the 2nd input.

    The solution is to pull those fields out of the language tabs.


Log in to reply
 

Looks like your connection to AsgardCms was lost, please wait while we try to reconnect.