Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Then, adding a "Custom HTML" element into the form and copy the following script into the "Custom HTML" property. 

Code Block
<script>
    $(function() {
        $( "[name$=city]" ).autocomplete({
            source: function( request, response ) {
                $.ajax({
                    url: "http://ws.geonames.org/searchJSON",
                    dataType: "jsonp",
                    data: {
                        featureClass: "P",
                        style: "full",
                        maxRows: 12,
                        name_startsWith: request.term
                    },
                    success: function( data ) {
                        response( $.map( data.geonames, function( item ) {
                            return {
                                label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                                value: item.name
                            }
                        }));
                    }
                });
            },
            minLength: 2
        });
    });
</script>


Figure 2 : Adding a "Custom HTML" element to the form and putting in the script in "Custom HTML" property.

Tip

Wiki Markup
1. The js library file of jQuery and jQueryUI are included in Joget form by default.
2. Please note that the "city" in "\[[name$=city]\]" in the code must be same with your Field Id. 

After add the script, click on the "Preview" of Form Builder. you can type "kua" and you will have text field show as the picture below. Image Added
Figure 3 : Preview and check the auto complete field is working or not.

The Auto Complete Text Field is working but it looked a little bit ugly. Next, I will add the following css in the "Custom HTML" element to make the Auto Complete Field look nicer.

Code Block
<style>
    .ui-autocomplete {
        background:#fff;
        border:#000 1px solid;
        list-style:none;
        padding: 5px;
        width: 250px;
    }
    .ui-menu-item:hover{
        background:#9CE9FF;
    }
</style>

Image Added
Figure 3 : The completed Auto Complete Field.