Skip to content

Options to format SendForm item list#450

Open
fcsobel wants to merge 1 commit intowojodesign:masterfrom
fcsobel:master
Open

Options to format SendForm item list#450
fcsobel wants to merge 1 commit intowojodesign:masterfrom
fcsobel:master

Conversation

@fcsobel
Copy link
Copy Markdown

@fcsobel fcsobel commented Feb 16, 2014

Add SendForm options itemFormat & indexStart to allow list formatting.

Ex: Can be used to format POST for simple asp.net mvc model binding:

        simpleCart({
            checkout: {
                type: "SendForm",
                url: "/checkout",
                method: "POST",
                itemFormat: 'items[{index}].{name}',
                indexStart: 0
            }
        });

Results in post that will bind to list of items:
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/

  items[0].name
  items[0].quantity
  items[0].price
  items[0].options
  items[1].name
  items[1].quantity
  items[1].price
  items[1].options
  ...etc

Example c# checkout model

    public class CheckoutModel
    {
        public string Currency { get; set; }
        public decimal Tax { get; set; }
        public decimal TaxRate { get; set; }
        public int ItemCount { get; set; }
        public List<CartItem> Items { get; set; }
    }

    public class CartItem
    {   
        public string Name { get; set; }
        public int Quantity { get; set; }
        public decimal Price { get; set; }
        public string Options { get; set; }
    }

Add SendForm options to allow item formatting setting index start. 

Ex used for mvc model binder:
    type: "SendForm",
    itemFormat: 'items[{index}].{name}',
    indexStart: 0

Results in:
  items[0].name
  items[0].quantity
  items[0].price
  items[0].options
  items[1].name
  items[1].quantity
  items[1].price
  items[1].options
  ...etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant