XLFormDescriptor.h 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // XLFormDescriptor.h
  3. // XLForm ( https://github.com/xmartlabs/XLForm )
  4. //
  5. // Copyright (c) 2015 Xmartlabs ( http://xmartlabs.com )
  6. //
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining a copy
  9. // of this software and associated documentation files (the "Software"), to deal
  10. // in the Software without restriction, including without limitation the rights
  11. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. // copies of the Software, and to permit persons to whom the Software is
  13. // furnished to do so, subject to the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be included in
  16. // all copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. // THE SOFTWARE.
  25. #import "XLFormSectionDescriptor.h"
  26. #import "XLFormRowDescriptor.h"
  27. #import "XLFormDescriptorDelegate.h"
  28. #import <Foundation/Foundation.h>
  29. extern NSString * __nonnull const XLFormErrorDomain;
  30. extern NSString * __nonnull const XLValidationStatusErrorKey;
  31. typedef NS_ENUM(NSInteger, XLFormErrorCode)
  32. {
  33. XLFormErrorCodeGen = -999,
  34. XLFormErrorCodeRequired = -1000
  35. };
  36. typedef NS_OPTIONS(NSUInteger, XLFormRowNavigationOptions) {
  37. XLFormRowNavigationOptionNone = 0,
  38. XLFormRowNavigationOptionEnabled = 1 << 0,
  39. XLFormRowNavigationOptionStopDisableRow = 1 << 1,
  40. XLFormRowNavigationOptionSkipCanNotBecomeFirstResponderRow = 1 << 2,
  41. XLFormRowNavigationOptionStopInlineRow = 1 << 3,
  42. };
  43. @class XLFormSectionDescriptor;
  44. @interface XLFormDescriptor : NSObject
  45. @property (readonly, nonatomic, nonnull) NSMutableArray * formSections;
  46. @property (readonly, nullable) NSString * title;
  47. @property (nonatomic) BOOL endEditingTableViewOnScroll;
  48. @property (nonatomic) BOOL assignFirstResponderOnShow;
  49. @property (nonatomic) BOOL addAsteriskToRequiredRowsTitle;
  50. @property (getter=isDisabled) BOOL disabled;
  51. @property (nonatomic) XLFormRowNavigationOptions rowNavigationOptions;
  52. @property (weak, nullable) id<XLFormDescriptorDelegate> delegate;
  53. +(nonnull instancetype)formDescriptor;
  54. +(nonnull instancetype)formDescriptorWithTitle:(nullable NSString *)title;
  55. -(void)addFormSection:(nonnull XLFormSectionDescriptor *)formSection;
  56. -(void)addFormSection:(nonnull XLFormSectionDescriptor *)formSection atIndex:(NSUInteger)index;
  57. -(void)addFormSection:(nonnull XLFormSectionDescriptor *)formSection afterSection:(nonnull XLFormSectionDescriptor *)afterSection;
  58. -(void)addFormRow:(nonnull XLFormRowDescriptor *)formRow beforeRow:(nonnull XLFormRowDescriptor *)afterRow;
  59. -(void)addFormRow:(nonnull XLFormRowDescriptor *)formRow beforeRowTag:(nonnull NSString *)afterRowTag;
  60. -(void)addFormRow:(nonnull XLFormRowDescriptor *)formRow afterRow:(nonnull XLFormRowDescriptor *)afterRow;
  61. -(void)addFormRow:(nonnull XLFormRowDescriptor *)formRow afterRowTag:(nonnull NSString *)afterRowTag;
  62. -(void)removeFormSectionAtIndex:(NSUInteger)index;
  63. -(void)removeFormSection:(nonnull XLFormSectionDescriptor *)formSection;
  64. -(void)removeFormRow:(nonnull XLFormRowDescriptor *)formRow;
  65. -(void)removeFormRowWithTag:(nonnull NSString *)tag;
  66. -(nullable XLFormRowDescriptor *)formRowWithTag:(nonnull NSString *)tag;
  67. -(nullable XLFormRowDescriptor *)formRowAtIndex:(nonnull NSIndexPath *)indexPath;
  68. -(nullable XLFormRowDescriptor *)formRowWithHash:(NSUInteger)hash;
  69. -(nullable XLFormSectionDescriptor *)formSectionAtIndex:(NSUInteger)index;
  70. -(nullable NSIndexPath *)indexPathOfFormRow:(nonnull XLFormRowDescriptor *)formRow;
  71. -(nonnull NSDictionary *)formValues;
  72. -(nonnull NSDictionary *)httpParameters:(nonnull XLFormViewController *)formViewController;
  73. -(nonnull NSArray *)localValidationErrors:(nonnull XLFormViewController *)formViewController;
  74. -(void)setFirstResponder:(nonnull XLFormViewController *)formViewController;
  75. -(nullable XLFormRowDescriptor *)nextRowDescriptorForRow:(nonnull XLFormRowDescriptor *)currentRow;
  76. -(nullable XLFormRowDescriptor *)previousRowDescriptorForRow:(nonnull XLFormRowDescriptor *)currentRow;
  77. -(void)forceEvaluate;
  78. @end