Starcounter / Starcounter.Uniform

Helper library for server-side part of uniform components.
MIT License
0 stars 0 forks source link

Add uni-form-item helper part #6

Closed PatrykSzwer closed 6 years ago

PatrykSzwer commented 6 years ago

I added: FormItemMessagesBuilder - recieves properties that user wants to have form messages and creates view-model object with proper schema. FormItemMessages - View-model of ItemMessages object, contains all methods that end user should use to set, get, and clear messages. FormItemMessage - class that represents message object, which is returned when getting a message. MessageContainer - Container that contains properties schema representations and allows to perform operations on them.

How to use:

  1. Add container object to the view-model json: "ItemMessages": {}
  2. In view-model code behind:

        static FormItemPage()
        {
            DefaultTemplate.ItemMessages.InstanceType = typeof(ItemMessages);
        }
    
        public void Init()
        {
            this.ItemMessages = new FormItemMessagesBuilder().ForProperty(nameof(this.Word)).Build();
        }
  3. Start using it!
    void Handle(Input.Word action)
        {
            if (action.Value.Length == 0)
            {
                this.ItemMessages.SetMessage(nameof(this.Word), "Word cannot be empty!", MessageType.Invalid);
            }
        }
PatrykSzwer commented 6 years ago

I applied all requested changes. Please check.

PatrykSzwer commented 6 years ago

Newly requested changes applied. Please check.