Creating a custom field for creating coordinates via google maps

edited April 2013 in Modules
I know how to use google maps and bind the 'dragend' event to populate fields with the coordinates.
However I am having difficulty using the Base_module_model to store and retrieve the values I wish to. I was not able to work out the "Custom Fields Objects" as the guide on that part is quite sparse.
First I used the "point" type of mysql to store the coordinates. I could select the value as `concat(x(coordinates),y(coordinates)) AS coordinates`. However the "point" type doesn't seem to be in the base_models, how could I extend this?
Further, how would I load custom JS to load on the display of the module form?

Right now I resolved to using 2 separate decimal fields to store the coordinates and enter them manual. Not very elegant :(

Really appreciate any help

Comments

  • edited 7:22PM
    Are you looking for a "point" type field generated by Form_builder? If so, there currently isn't one but this sounds like an opportunity to add one. I haven't really worked with that field type before, so what were you envisioning that field type looking like and what would be an example value? When we've worked with maps in the past we've used floating point field types to store lat and lng.

    If you are using the 1.0 beta, you can create a custom field type that gets attached to Form_builder which allows you to associate js and css to a particular field type. There is a "forms" section in the 1.0 User Guide that talks a bit more about custom field types:
    https://github.com/daylightstudio/FUEL-CMS-User-Guide-Module
  • edited 7:22PM
    I imagine the most basic representation would be a text-field with concated lat/long values, e.g: "31.456,121.453" the key though is reading from and storing back to the database. As of now a point field get's represented in garbled binary data or something.
    After that is working a possible parameter would be to enable Google maps, and in that case the field becomes hidden and coordinates get loaded to a dragable pinpoint which updates the hidden field on dragend.

    Thanks for pointing me to the new guide, but like my question about no wysiwyg I am unable to successfully use a custom field in context of my module models. The guide only seems to cover how to set up a form for the frontend, rather than the CMS and the magic modules.

    Also while using the guide and trying to access /fuel/tools/user_guide/libraries/form_builder throws this error:

    Fatal error: Cannot redeclare class Form_builder in modules\fuel\libraries\Form_builder.php on line 43
  • edited 7:22PM
    To create a custom form field type I'd recommend the following:
    1. Create a class or function that contains the logic for creating the field. The fuel/modules/fuel/libraries/Fuel_custom_fields.php is a good place to look as an example. A $param of options will get passed to your method or function which will include an 'instance' parameter that represents the Form_builder class instance that's generating the form.
    2. Map that class/function using the fuel/application/config/custom_fields.php config file. There is more information that can be found here in your user guide installation:
    fuel/tools/user_guide/general/forms#association_parameters
    // multi field $fields['multi'] = array( 'class' => 'My_class', 'function' => 'point', 'js' => array('my_js'), 'js_function' => 'my_js_function', 'css' => array('my_css'), 'represents' => 'point', );
    3. Now use your new field in your model's form_field method:
    ... $fields['my_point'] = array('type' => 'point');

    With regards to the Form_builder error, I'm not able to replicate that at the moment. What is your setup? Do you get that error on any of the FUEL Specific Classes?
  • edited 7:22PM
    Hey this was a great help, thanks again. I had a bit of a vacation in between this :D
    I was able to set everything up for my requirements, however not able to use MySQL point value I went back to using two decimal fields.
Sign In or Register to comment.