chrismiles / EZForm

iOS form handling and validation library.
MIT License
284 stars 64 forks source link

Add EZFormInputAccessoryTypeDone (hides prev/next input accessory buttons) #52

Closed stephsharp closed 10 years ago

stephsharp commented 10 years ago

I added additional EZFormInputAccessoryTypes (EZFormInputAccessoryTypeDone and EZFormInputAccessoryTypeDoneLeftAligned) to give the option of only showing a Done button in a form's input accessory view. The standard input accessory type also has previous and next buttons, which aren't necessary in forms where only one field can become the first responder.

Here's the situation where these new types would be useful:

You have a form with multiple fields where canBecomeFirstResponder equals NO (and these fields are therefore skipped over by the previous/next buttons in the input accessory view). For example: EZFormRadioField, EZFormBooleanField and EZFormContinuousField.

You have only one field in the form where canBecomeFirstResponder == YES, and the input view for this field cannot dismiss itself. For example:

In these cases it's useful to have a Done button to dismiss the input view, but the previous/next buttons on the input accessory view are unnecessary.

I'm not sure if this situation occurs all that often, but I needed these extra EZFormInputAccessoryTypes in my current project (where I have a form with multiple radio fields and one text field). Any feedback would be great. Thanks!

amcastror commented 10 years ago

Hi! I was looking for this exact feature (actually started coding before seeing this). I got into this issue when using a date field with an UIDatePicker. Nice work @stephsharp!

@chrismiles, can you merge this please? I would like to continue using the master branch.

Thanks a lot!

stephsharp commented 10 years ago

@amcastror I'm glad someone else found it useful!

jessedc commented 10 years ago

Looks like a good addition. Thanks @stephsharp! Are there any changes that would be needed to demonstrate the feature in the demo application?

amcastror commented 10 years ago

@jessedc , on the EZFDRegistrationFormViewController.m you can change (or leave a commented line) with the change:

    _registrationForm = [[EZForm alloc] init];
    _registrationForm.inputAccessoryType = EZFormInputAccessoryTypeDone;
    _registrationForm.delegate = self;

Or with the commented line:

    _registrationForm = [[EZForm alloc] init];

    /*
     * To hide the prev and next buttons, change the type to:
     *  _registrationForm.inputAccessoryType = EZFormInputAccessoryTypeDone;
     */
    _registrationForm.inputAccessoryType = EZFormInputAccessoryTypeStandard;
    _registrationForm.delegate = self;

That makes the example work with no navigation buttons.

Is that ok?

stephsharp commented 10 years ago

@amcastror Good suggestion, but I would probably change the inputAccessoryType in the Simple Login Form instead. It only has 2 fields and doesn't scroll, so the prev/next buttons wouldn't be missed so much.

EZFDSimpleLoginFormViewController: EZFormInputAccessoryTypeDone EZFDRegistrationFormViewController: EZFormInputAccessoryTypeStandard EZFDScrollViewFormViewController: EZFormInputAccessoryTypeStandardLeftAligned

@jessedc your thoughts?

jessedc commented 10 years ago

@stephsharp lets do what you suggested. Could you make that change and add it to your PR? Then we can merge it.

stephsharp commented 10 years ago

@jessedc done

amcastror commented 10 years ago

Nice! Thanks a lot @stephsharp.

@jessedc, could you please merge this? I would love to stop using my custom fix. Thanks!

amcastror commented 10 years ago

Hi, Sory to be annoying @jessedc , but can you please merge this?

Thanks a lot!

jessedc commented 10 years ago

I just want to have a look before I merge it. I will get to it this weekend ;) I really appreciate the reminder! :rocket: