 class Stall.AddToCartForm extends Vertebra.View
   @create = ($el) ->
-    unless (instance = $el.data('stall.add-to-cart-form'))
-      instance = new Stall.AddToCartForm(el: $el)
-      $el.data('stall.add-to-cart-form', instance)
+    unless (form = $el.data('stall.add-to-cart-form'))
+      form = new Stall.AddToCartForm(el: $el)
+      $el.data('stall.add-to-cart-form', form)
 
-    instance.sendRequest()
+    form
+
+  @validate = ($el) ->
+    form = Stall.AddToCartForm.create($el)
+    form.validate()
+
+  @sendRequest = ($el) ->
+    form = Stall.AddToCartForm.create($el)
+    form.sendRequest()
 
   events:
     'ajax:success': 'onSuccess'

  displayErrorMessages: (options) ->
    messages = (@errorMessages[error] for error in @errors)
    message = messages.join('<br>')
    @$button.attr(title: message)
    @$button.tooltip(html: true)
    # Force tooltip display if the user just submitted the form
    @$button.tooltip('show') if options.submit
    @$button.prop('disabled', true)

    @errorMessages = @$el.data('error-messages')

  sendRequest: ->
    unless (v = @validate(submit: true)) and (e = !@errors.length)
      console.log 'sendRequest', v, e
      return false
    @setLoading(true)
    true

