uadmin.F

Back to Customizing Records Page

F is a field.

Structure:

type F struct {
    Name              string
    DisplayName       string
    ColumnName        string
    Type              string
    TypeName          string
    Value             interface{}
    Help              string
    Max               interface{}
    Min               interface{}
    Format            string
    DefaultValue      string
    Required          bool
    Pattern           string
    PatternMsg        string
    Hidden            bool
    ReadOnly          string
    Searchable        bool
    Filter            bool
    ListDisplay       bool
    FormDisplay       bool
    CategoricalFilter bool
    Translations      []translation
    Choices           []Choice
    IsMethod          bool
    ErrMsg            string
    ProgressBar       map[float64]string
    LimitChoicesTo    func(interface{}, *User) []Choice
    UploadTo          string
    Encrypt           bool
    Approval          bool
    NewValue          interface{}
    OldValue          interface{}
    ChangedBy         string
    ChangeDate        *time.Time
    ApprovalAction    ApprovalAction
    ApprovalDate      *time.Time
    ApprovalBy        string
    ApprovalID        uint
    Stringer          bool
}

Parameters:

  • Name - The name of the field
  • DisplayName - The name that you want to display in the model. It is an alias name.
  • ColumnName - The column name of the field
  • Type - The field type (e.g. file, list, progress_bar)
  • TypeName - The data type of the field (e.g. string, int, float64)
  • Value - The value that you want to assign in a field
  • Help - An instruction given to understand more details about the field or how to assign a value in a field
  • Max - The maximum value the user can assign. It is applicable for numeric characters.
  • Min - The minimum value the user can assign. It is applicable for numeric characters.
  • Format - Implements formatted I/O with functions (e.g. %s - string, %d - Integer)
  • DefaultValue - A value assigned automatically if you want to add a new record
  • Required - A field that user must perform the given task(s). It cannot be skipped or left empty.
  • Pattern - A regular expression
  • PatternMsg - An error message if the user assigns a value that did not match the requested format
  • Hidden - A feature to hide the component in the editing section of the form
  • ReadOnly - A field that cannot be modified
  • Searchable - A feature that allows the user to search for a field or column name
  • Filter - A feature that allows the user to filter the record assigned in a model
  • ListDisplay - A feature that will hide the field in the viewing section of the model if the value returns false
  • FormDisplay - A feature that will hide the field in the editing section of the model if the value returns false
  • CategoricalFilter - A feature that allows the user to filter the record assigned in a model in the form of combo box
  • Translations - For multilingual fields
  • Choices - A struct for the list of choices
  • IsMethod - Check if the method should be included in the field list
  • ErrMsg - An error message displayed beneath the input field
  • ProgressBar - A feature used to measure the progress of the activity
  • LimitChoicesTo - A feature used to append the fetched records in the drop down list
  • UploadTo - A path where to save the uploaded files
  • Encrypt - A feature used to encrypt the value in the database
  • Approval - A feature used to set an approval permission in the field
  • NewValue - A value that you want to replace from the old value
  • OldValue - A value that was assigned before
  • ChangedBy - Returns the username who changed the value of the field record
  • ChangeDate - The date when the value of the field record was changed
  • ApprovalAction - A selection of approval actions. There are two selections: Approved and Declined.
  • ApprovalDate - The date when the value of the field record was approved
  • ApprovalBy - Returns the username who approved the value of the field record
  • ApprovalID - Returns the user ID who approved the value of the field record
  • Stringer - A feature that assigns a field as a unique type

There are 2 ways you can do for initialization process using this function: one-by-one and by group.

One-by-one initialization:

func main(){
    // Some codes
    f := uadmin.F{}
    f.Name = "Name"
    f.DisplayName = "DisplayName"
    f.ColumnName = "column_name"
    f.Type = "Type"
    f.Value = "Value"
}

By group initialization:

func main(){
    // Some codes
    f := uadmin.F{
        Name:        "Name",
        DisplayName: "DisplayName",
        ColumnName: "name",
        Type:        "Type",
        Value:       "Value",
    }
}

In the following examples, we will use “by group” initialization process.

Example #1: String Data Type

Back to Top

In this example, we will discuss the following:

  • Change the actual name that is different from the name initialized in the model struct
  • Assign a value automatically if you are creating a new record
  • Assign a help note to instruct the user what to do on that field
  • Set the field as Required
  • Set a pattern and error message where only letters are acceptable
  • Hide the field in the form and list
  • Disable editing in a field
  • Allows searching and filtering record(s)
  • Adding an error message tag
  • Encrypt the value of the name in the database

Name Field in Category Model - DisplayName

Back to Top (Example #1)

Now let’s replace the actual field name. In order to do that, declare a value in the DisplayName field inside uadmin.F function then assign that value to the DisplayName field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        DisplayName: "Category Name",
    }

    // Some codes

    // Assign the DisplayName field value to the Name field in Category
    // model
    category.DisplayName = modelschemafield.DisplayName
}

Run your application and go to Category model. As expected, the name has changed to “CATEGORY NAME”.

../../_images/categorydisplayname.png

Name Field in Category Model - DefaultValue

Back to Top (Example #1)

You can also assign a value in the Name field automatically when creating a new record. In order to do that, declare a value in the DefaultValue field inside uadmin.F function then assign that value to the DefaultValue field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        DefaultValue: "Type here",
    }

    // Some codes

    // Assign the DefaultValue field value to the Name field in Category
    // model
    category.DefaultValue = modelschemafield.DefaultValue
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, “Type here” value has assigned automatically in the Name field.

../../_images/categorydefaultvalue.png

Name Field in Category Model - Help

Back to Top (Example #1)

Let’s assign a help note in the Name field to instruct the user what to do on that field. In order to do that, declare a value in the Help field inside uadmin.F function then assign that value to the Help field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        Help: "Input a category name for your Todo List.",
    }

    // Some codes

    // Assign the Help field value to the Name field in Category model
    category.Help = modelschemafield.Help
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, the help note was displayed below the input Name field.

../../_images/categorynamehelp.png

Name Field in Category Model - Required

Back to Top (Example #1)

Let’s set a feature where the user needs to fill up the Name field. If the value is empty, the user will prompt the user that the value of the Name field should be assigned. In order to do that, declare a value in the Required field inside uadmin.F function then assign that value to the Required field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        Required: true,
    }

    // Some codes

    // Assign the Required field value to the Name field in Category
    // model
    category.Required = modelschemafield.Required
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. If you notice, there is an asterisk (*) symbol located on the top right after the “Name:”. Let’s leave the Name field value as it is. If you click Save, the system will prompt the user that the Name must be filled out.

../../_images/categorynamerequired.png

Name Field in Category Model - Pattern and PatternMsg

Back to Top (Example #1)

Let’s set a feature where the user can assign letters only in the Name field. In order to do that, declare a value in the Required field inside uadmin.F function then assign that value to the Required field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        Pattern:      "^[a-zA-Z _]*$",
        PatternMsg:   "Your input must be a letter.",
    }

    // Some codes

    // Assign the Pattern field value to the Name field in Category model
    category.Pattern = modelschemafield.Pattern

    // Assign the PatternMsg field value to the Name field in Category
    // model
    category.PatternMsg = modelschemafield.PatternMsg
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. Let’s assign a numeric value in the Name field. If you click Save, the system will prompt the user the the value of the Name field must assign letters only.

../../_images/categorynamepattern.png

Name Field in Category Model - Searchable

Back to Top (Example #1)

Let’s set a feature where the user can search the name in the Category model. In order to do that, declare a value in the Searchable field inside uadmin.F function then assign that value to the Searchable field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        Searchable:   true,
    }

    // Some codes

    // Assign the Searchable field value to the Name field in Category model
    category.Searchable = modelschemafield.Searchable
}

Run your application and go to the Category model. As expected, there is a search engine at the top of the model form. Suppose you have two records as shown below:

../../_images/categorysearchable.png

Let’s search “Work” and see what happens.

../../_images/categorysearchablework.png

Name Field in Category Model - Filter and CategoricalFilter

Back to Top (Example #1)

Let’s set a feature where the user can filter the name in the Category model. In order to do that, declare a value in the Filter and CategoricalFilter fields inside uadmin.F function then assign that value to those fields in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        Filter:            true,
        CategoricalFilter: true,
    }

    // Some codes

    // Assign the Filter field value to the Name field in Category model
    category.Filter = modelschemafield.Filter

    // Assign the CategoricalFilter field value to the Name field in
    // Category model
    category.CategoricalFilter = modelschemafield.CategoricalFilter
}

Run your application and go to the Category model. As expected, the combo box form highlighted on the right side is the CategoricalFilter to notify the user that the Category Name is the field that will be filtered. Now click the Filter button. Suppose you have two records as shown below:

../../_images/categoryfilter.png

Assign “Work” in the Category Name. Click Filter button on the bottom right corner of the modal and see what happens.

../../_images/categoryfilterwork.png

As expected, the Category record has filtered out where the name contains “Work”.

../../_images/categorynamefilterresult.png

Name Field in Category Model - ReadOnly

Back to Top (Example #1)

Let’s set a feature where the user cannot modify a Name field in the Category model. In order to do that, declare a value in the ReadOnly field inside uadmin.F function then assign that value to the ReadOnly field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        ReadOnly: "true",
    }

    // Some codes

    // Assign the ReadOnly field value to the Name field in Category model
    category.ReadOnly = modelschemafield.ReadOnly
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, the Name field is now Read Only that means the value cannot be modified.

../../_images/categorynamereadonly.png

Name Field in Category Model - ErrMsg

Back to Top (Example #1)

Let’s set a feature where an error message will be displayed beneath the input Name field. In order to do that, declare a value in the ErrMsg field inside uadmin.F function then assign that value to the ErrMsg field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        ErrMsg: "This field cannot be modified.",
    }

    // Some codes

    // Assign the ErrMsg field value to the Name field in Category model
    category.ErrMsg = modelschemafield.ErrMsg
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, the error message was displayed beneath the input Name field.

../../_images/categorynameerrmsg.png

Name Field in Category Model - ListDisplay

Back to Top (Example #1)

Let’s set a feature that will hide the field or column name in the viewing section of the Category model. In order to do that, declare a value in the ListDisplay field inside uadmin.F function then assign that value to the ListDisplay field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        ListDisplay: false,
    }

    // Some codes

    // Assign the ListDisplay field value to the Name field in Category
    // model
    category.ListDisplay = modelschemafield.ListDisplay
}

Run your application and go to the Category model. As expected, the Name Field in Category Model is now invisible in the list.

../../_images/categorynamelistdisplay.png

Name Field in Category Model - FormDisplay

Back to Top (Example #1)

Let’s set a feature that will hide the field in the editing section of the Category model. In order to do that, declare a value in the FormDisplay field inside uadmin.F function then assign that value to the FormDisplay field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        FormDisplay: false,
    }

    // Some codes

    // Assign the FormDisplay field value to the Name field in Category
    // model
    category.FormDisplay = modelschemafield.FormDisplay
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, the Name Field is now invisible in the Category model.

../../_images/categorynameformdisplay.png

Name Field in Category Model - Hidden

Back to Top (Example #1)

Unlike in FormDisplay, the field will hide if the value is true. In order to hide the Name field in the Category model, declare a value in the Hidden field inside uadmin.F function then assign that value to the Hidden field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        Hidden: true,
    }

    // Some codes

    // Assign the Hidden field value to the Name field in Category model
    category.Hidden = modelschemafield.Hidden
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, the Name Field is now invisible in the Category model.

../../_images/categorynameformdisplay.png

Name Field in Category Model - Encrypt

Back to Top (Example #1)

Suppose you have two records as shown below:

../../_images/categorynametworecords.png

Let’s encrypt the value of the Name field in the Category Model. In order to do that, declare a value in the Encrypt field inside uadmin.F function then assign that value to the Encrypt field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        Encrypt: true,
    }

    // Some codes

    // Assign the Encrypt field value to the Name field in Category model
    category.Encrypt = modelschemafield.Encrypt
}

Run your application. From your project folder, open uadmin.db with DB Browser for SQLite.

../../_images/uadmindbsqlite.png

Click on Execute SQL.

../../_images/executesqlhighlighted.png

Get all records by typing this command: SELECT * FROM categories then click the right arrow icon to execute your SQL command.

../../_images/selectfromcategories.png

As expected, the Name value is encrypted in the database.

../../_images/categorynameencrypt.png

Example #2: Progress Bar

Back to Top

In this example, we will discuss the following:

  • Change the actual name that is different from the name initialized in the model struct
  • Set the type of the input field
  • Set the color and maximum value in the progress bar
  • Set the minimum and maximum limit the user can assign in the progress bar
  • Assign a value automatically if you are creating a new record

Progress Field in Todo Model - DisplayName

Back to Top (Example #2)

Now let’s replace the actual field name. In order to do that, declare a value in the DisplayName field inside uadmin.F function then assign that value to the DisplayName field in the Todo model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        DisplayName: "Current Progress",
    }

    // Some codes

    // Assign the DisplayName field value to the Progress field in Todo
    // model
    todo.DisplayName = modelschemafield.DisplayName
}

Run your application and go to the Todo model. As expected, the name has changed to “CURRENT PROGRESS”.

../../_images/todoprogressdisplayname.png

Progress Field in Todo Model - Type

Back to Top (Example #2)

Let’s convert the input type to the progress bar. In order to do that, declare a value in the Type field inside uadmin.F function then assign that value to the Type field in the Todo model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        Type: "progress_bar",
    }

    // Some codes

    // Assign the Type field value to the Progress field in Todo model
    todo.Type = modelschemafield.Type
}

Run your application and go to the Todo model. As expected, the field type has changed from regular to a progress bar. However, the appearance does not look good because we have not assigned the value and color of the progress bar yet.

../../_images/todoprogresstype.png

Progress Field in Todo Model - ProgressBar

Back to Top (Example #2)

Let’s assign the value and the color of the progress bar. In order to do that, declare a value in the ProgressBar field inside uadmin.F function then assign that value to the ProgressBar field in the Todo model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes

        // 100.0 - maximum value
        // #07c - blue color
        ProgressBar: map[float64]string{100.0: "#07c"},
    }

    // Some codes

    // Assign the ProgressBar field value to the Progress field in Todo
    // model
    todo.ProgressBar = modelschemafield.ProgressBar
}

Run your application and go to the Todo model. As expected, the appearance of the progress bar is now good enough.

../../_images/todoprogressbar.png

Progress Field in Todo Model - Max and Min

Back to Top (Example #2)

Let’s set a limitation where the user can assign a value between the range of 0 and 100. In order to do that, declare a value in the Max and Min fields inside uadmin.F function then assign that value to those fields in the Todo model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        Max: "100",
        Min: "0",
    }

    // Some codes

    // Assign the Max field value to the Progress field in Todo model
    todo.Max = modelschemafield.Max

    // Assign the Min field value to the Progress field in Todo model
    todo.Min = modelschemafield.Min
}

Run your application and go to the Todo model. Let’s put a numeric value outside the range of 0 and 100 in the Progress field and see what happens.

../../_images/todoprogressmax.png

Progress Field in Todo Model - DefaultValue

Back to Top (Example #2)

You can also assign a value in the Progress field automatically when creating a new record. In order to do that, declare a value in the DefaultValue field inside uadmin.F function then assign that value to the DefaultValue field in the Todo model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        DefaultValue: "50",
    }

    // Some codes

    // Assign the DefaultValue field value to the Progress field in Todo
    // model
    todo.DefaultValue = modelschemafield.DefaultValue
}

Run your application, go to the Todo model and click Add New Todo button on the top right corner of the screen. As expected, “50” value has assigned automatically in the Progress field.

../../_images/todoprogressdefaultvalue.png

Example #3: Choices

Back to Top

In this example, we will discuss the following:

  • Build choices
  • Hide the field in the form and list

Nationality Field in Friend Model - Choices

Back to Top (Example #3)

Let’s build a choice that includes Chinese and Filipino and excludes Others. In order to do that, declare a value in the Choices field inside uadmin.F function then assign that value to the Choices field in the Friend model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes

        // K is the ID of the choice
        // V is the value of the choice
        Choices: []uadmin.Choice{
            {K: 0, V: " - "},
            {K: 1, V: "Chinese"},
            {K: 2, V: "Filipino"},
        },
    }

    // Some codes

    // Assign the Choices field value to the Nationality field in Friend
    // model
    friend.Choices = modelschemafield.Choices
}

Run your application, go to the Friend model and click Add New Friend button on the top right corner of the screen. As expected, Chinese and Filipino choices are included in the list.

../../_images/friendnationalitychoices.png

Nationality Field in Friend Model - ListDisplay

Back to Top (Example #3)

Let’s set a feature that will hide the field or column name in the viewing section of the Friend model. In order to do that, declare a value in the ListDisplay field inside uadmin.F function then assign that value to the ListDisplay field in the Friend model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        ListDisplay: false,
    }

    // Some codes

    // Assign the ListDisplay field value to the Nationality field in
    // Friend model
    friend.ListDisplay = modelschemafield.ListDisplay
}

Run your application and go to the Friend model. As expected, the Nationality Field in the Friend Model is now invisible in the list.

../../_images/friendnationalitylistdisplay.png

Nationality Field in Friend Model - FormDisplay

Back to Top (Example #3)

Let’s set a feature that will hide the field in the editing section of the Friend model. In order to do that, declare a value in the FormDisplay field inside uadmin.F function then assign that value to the FormDisplay field in the Friend model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        FormDisplay: false,
    }

    // Some codes

    // Assign the FormDisplay field value to the Nationality field in
    // Friend model
    friend.FormDisplay = modelschemafield.FormDisplay
}

Run your application, go to the Friend model and click Add New Friend button on the top right corner of the screen. As expected, the Nationality Field is now invisible in the Friend model.

../../_images/friendnationalityformdisplay.png

Nationality Field in Friend Model - Hidden

Back to Top (Example #3)

Unlike in FormDisplay, the field will hide if the value is true. In order to hide the Name field in the Category model, declare a value in the Hidden field inside uadmin.F function then assign that value to the Hidden field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        Hidden: true,
    }

    // Some codes

    // Assign the Hidden field value to the Nationality field in Friend
    // model
    friend.Hidden = modelschemafield.Hidden
}

Run your application, go to the Friend model and click Add New Friend button on the top right corner of the screen. As expected, the Nationality Field is now invisible in the Friend model.

../../_images/friendnationalityformdisplay.png

Example #4: Upload To

Back to Top

In this example, we will discuss the following:

  • Set the type of the input field
  • Set the field as Required
  • Set a path where to upload the files
  • Adding an error message tag
  • Hide the field in the form and list

File Field in Category Model - Type

Back to Top (Example #4)

Let’s convert the input type to the file. In order to do that, declare a value in the Type field inside uadmin.F function then assign that value to the Type field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        Type: "file",
    }

    // Some codes

    // Assign the Type field value to the File field in Category model
    category.Type = modelschemafield.Type
}

Run your application and go to the Category model. As expected, the field type has changed from regular to a file input.

../../_images/categoryfiletype.png

File Field in Category Model - Required

Back to Top (Example #4)

Let’s set a feature where the user needs to fill up the File field. If the value is empty, the user will prompt the user that the value of the File field should be assigned. In order to do that, declare a value in the Required field inside uadmin.F function then assign that value to the Required field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        Required: true,
    }

    // Some codes

    // Assign the Required field value to the File field in Category model
    category.Required = modelschemafield.Required
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. If you notice, there is an asterisk (*) symbol located on the top right after the “File:”. Let’s leave the File field value as it is. If you click Save, nothing will happen until you fill out the File field.

../../_images/categoryfilerequired.png

File Field in Category Model - UploadTo

Back to Top (Example #4)

Let’s set a feature where the uploaded file will save in the specified path on your project folder. In order to do that, declare a value in the UploadTo field inside uadmin.F function then assign that value to the UploadTo field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        UploadTo: "/media/files/",
    }

    // Some codes

    // Assign the UploadTo field value to the File field in Category model
    category.UploadTo = modelschemafield.UploadTo
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. Let’s add a new record that includes the uploaded file from your computer (e.g. Windows Installation.pdf).

../../_images/categoryinstallationrecord1.png

Result:

../../_images/categoryinstallationrecordresult1.png

From your project folder, go to /media/files/(generated_folder_name)/. As expected, the “Windows Installation.pdf” file was saved on that path.

../../_images/categoryfileuploadto.png

File Field in Category Model - ErrMsg

Back to Top (Example #4)

Let’s set a feature where an error message will be displayed beneath the input File field. In order to do that, declare a value in the ErrMsg field inside uadmin.F function then assign that value to the ErrMsg field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        ErrMsg: "Invalid format",
    }

    // Some codes

    // Assign the ErrMsg field value to the File field in Category model
    category.ErrMsg = modelschemafield.ErrMsg
}

Run your application, go to the Category model and click the existing record that you have. As expected, the error message was displayed beneath the input File field.

../../_images/categoryfileerrmsg.png

File Field in Category Model - ListDisplay

Back to Top (Example #4)

Let’s set a feature that will hide the field or column name in the viewing section of the Category model. In order to do that, declare a value in the ListDisplay field inside uadmin.F function then assign that value to the ListDisplay field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        ListDisplay: false,
    }

    // Some codes

    // Assign the ListDisplay field value to the File field in Category
    // model
    category.ListDisplay = modelschemafield.ListDisplay
}

Run your application and go to the Category model. As expected, the File Field in the Category Model is now invisible in the list.

../../_images/categoryfilelistdisplay.png

File Field in Category Model - FormDisplay

Back to Top (Example #4)

Let’s set a feature that will hide the field in the editing section of the Category model. In order to do that, declare a value in the FormDisplay field inside uadmin.F function then assign that value to the FormDisplay field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        FormDisplay: false,
    }

    // Some codes

    // Assign the FormDisplay field value to the File field in Category
    // model
    category.FormDisplay = modelschemafield.FormDisplay
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, the File Field is now invisible in the Category model.

../../_images/categoryfileformdisplay.png

File Field in Category Model - Hidden

Back to Top (Example #4)

Unlike in FormDisplay, the field will hide if the value is true. In order to hide the File field in the Category model, declare a value in the Hidden field inside uadmin.F function then assign that value to the Hidden field in the Category model.

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        // Some codes
        Hidden: true,
    }

    // Some codes

    // Assign the Hidden field value to the File field in Category model
    category.Hidden = modelschemafield.Hidden
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, the File Field is now invisible in the Category model.

../../_images/categoryfileformdisplay.png

Example #5: Approval

Back to Top

In this example, we will discuss on how to set an approval permission in the field.

Suppose you have “johndoe” account in the User model that is not an admin.

../../_images/johndoerecord.png

User permissions are set for that user in Approvals and Friends models without an approval access.

../../_images/johndoeuserpermissionapproval.png

And you have the Name field in the Friend model that has a primary key of 1 as shown below:

../../_images/friendnamedefault.png

Go to main.go and apply the following codes below:

func main(){
    // Some codes

    // Field configurations
    field := uadmin.F{
        Name:     "Name",
        TypeName: "string", // Data Type
        Format:   "%s",     // String
        Approval: true,
    }

    // Model schema configurations
    modelschema := uadmin.ModelSchema{
        Name:      "Friend", // Model name
        ModelName: "friend", // URL
        ModelID:   1,        // Primary key
        Fields:    []uadmin.F{field},
    }

    // Call the field variable assigned in an array
    // Fields[0] = field
    modelschemafield := modelschema.Fields[0]

    // Call the schema of "friend" where the field name is "Name"
    // modelschema.ModelName = "friend"
    // modelschemafield.Name = "Name"
    friend := uadmin.Schema[modelschema.ModelName].FieldByName(modelschemafield.Name)

    // Assign the TypeName field value to the Name field in Friend model
    friend.TypeName = modelschemafield.TypeName

    // Assign the Format field value to the Name field in Friend model
    friend.Format = modelschemafield.Format

    // Assign the Approval field value to the Name field in Friend model
    friend.Approval = modelschemafield.Approval
}

Run your application and login your account using “johndoe”.

../../_images/johndoelogin.png

As you can see, only the Approvals and Friends models are accessible in the dashboard. It is based on the user permission that was assigned on that user. Now click on “FRIENDS”.

../../_images/friendsapprovalhighlighted.png

Click “Add New Friend” to create a new record.

../../_images/addnewfriend.png

Let’s input the following field for this record.

../../_images/johndoefriendrecord.png

Result

../../_images/johndoenameempty.png

Based on the result, the name does not show up because we need an approval to someone who has approval access. Now logout johndoe account then login an admin account.

../../_images/loginformadmin.png

From uAdmin dashboard, go to the Friends model, click the record that you have created, and in the input box of the Name field, there is a yellow warning sign on the left side that means it needs an approval to someone who has approval access. Now click the highlighted area below.

../../_images/johndoeapprovalbutton.png

The admin will review the record that was created by a “johndoe” user. If you think his record is satisfactory, choose Approved in Approval Action then click Save and Continue on the bottom right corner of the screen.

../../_images/johndoeapprovalreview.png

It is shown that the one who approved the record is an admin with an approved date. Now click View Record button to see the result.

../../_images/johndoeviewrecord.png

The input Name field has a checkmark sign that means the record created by “johndoe” was approved.

../../_images/johndoeapprovedrecord.png