Search code examples
google-app-maker

How to get the type of a field via Javascript : Google App Maker


How do I get the field type of a field in Google App Maker?

I have tried to find it via:

app.models.MODEL_NAME.fields.date

but there isn't a property type for a field.

So the question is how can I find the type of a field via Javascript?

Many thanks


Solution

  • Interesting question. Here is how I do it; Suppose I want to know what are all the field types of a model. I use this:

    var allFields = app.models.MODEL_NAME.fields._values;
    for( var f=0; f<allFields.length; f++) {
      var field = allFields[f];  
      var fieldType = field.__gwt_instance.b.B.j;
      console.log(fieldType);
    }
    

    So, in summary, all you have to do is get the field:

    var field = app.models.MODEL_NAME.fields.DESIRED_FIELD
    

    Then you just get the type like this:

    var fieldType = field.__gwt_instance.b.B.j;
    

    As I say, this works for me. I hope this works for you too!