headzoo / surf

Stateful programmatic web browsing in Go.
MIT License
1.49k stars 160 forks source link

Add input[checked], "select option" and textarea support. #3

Closed haruyama closed 9 years ago

haruyama commented 10 years ago

I want to set formerly-unchecked input[type=checkbox] value and etc. via form.Input(). This is why fields check in Input() is deleted.

haruyama commented 10 years ago

I think again that errors.NewElementNotFound() is useful. I add definedFileds to Form.

headzoo commented 10 years ago

We should look into setting non-existent form elements via the Input() method without removing the field checks. I want to be able to catch unintentionally setting a non-existent form fields. For instance when accidentally setting the name argument to "usernam" instead of "username", which could cause difficult to find bugs.

I assumed I would eventually add a Checkbox() method. That might be a better spot for manipulating checkboxes.

haruyama commented 10 years ago

Now my code checks field-existance in Input(), using Form.definedFields.

I also want to add "Checkbox(values []string, field string) error".

headzoo commented 10 years ago

I've been procrastinating on adding full support for checkboxes because they can be a little tricky at times. Just keep in mind that browsers don't submit unchecked checkboxes, and they need to be filtered out in Form.send().

haruyama commented 10 years ago

I don't know your "full support for checkboxes"....

I just added Form.InputSlice() and Form.Checkbox() which set multi-values to field. If you want to all-unchecked checkbox field, you set zero-length slice( []string{} ) as values. Or we will add Form.Delete(name string).

Note: My code does not validate checkbox values.

headzoo commented 10 years ago

I'll take a look at this patch shortly. I just go back from vacation and have some catching up to do.