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

info27117
info27117

Hi,

I have a model form and want to fill a field with the result of a calculation of 2 other fields.

In my model I have (incomplete code for sake of brevity):

public function filterFields($fields, $context = null)
{
    $location_string = $this->listing_city.'+'.$this->state;

    // Get lat and long based on $location_string

   $fields->listing_latitude->value = $lat;

  $fields->listing_longitude->value = $long;

}

This works great, except if the form is initially blank - ie new record..

In the case of a new record, once the Save button is pressed, the form reloads, and the lat and long fields are correctly filled in.

However, if I then call a page that displays a map using the entry's lat and long, ie:

 {{ record.listing_latitude }}

Then this is empty.

So it seems after the first save of the form, the lat and long fields are filled in, but not yet saved.

If the Save button is pressed again, then these fields are saved. But I don't want to rely on the user having to press Save twice.

Could someone please let me know how I can save these fields programmatically?

Also, I am quite new to October - if there is a better way to do this, suggestions are welcome.

Thanks ahead of time.

Last updated

1-1 of 1

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