Merge branch 'feature/form_checkbox' into 'develop'

Feature/form checkbox

See merge request BPHV_MIPS/mvm_core_ui!23
This commit is contained in:
Pfeil, Scott Robert 2019-04-30 16:05:50 -04:00
commit 138f82bc8c
8 changed files with 97 additions and 18 deletions

View File

@ -324,7 +324,7 @@
} }
// key used to send text value to server // key used to send text value to server
string = [map string:@"fieldKey"]; string = [map string:KeyFieldKey];
if (string.length > 0) { if (string.length > 0) {
self.fieldKey = string; self.fieldKey = string;
} }

View File

@ -20,7 +20,8 @@
static const CGFloat FaultTolerance = 20.f; static const CGFloat FaultTolerance = 20.f;
static const CGFloat CheckBoxHeightWidth = 18.0; static const CGFloat CheckBoxHeightWidth = 18.0;
@interface MVMCoreUICheckBox ()
@interface MVMCoreUICheckBox () <FormValidationProtocol, MVMCoreUIMoleculeViewProtocol>
@property (nonatomic, readwrite) BOOL isSelected; @property (nonatomic, readwrite) BOOL isSelected;
@property (weak, nonatomic) UIView *checkedSquare; @property (weak, nonatomic) UIView *checkedSquare;
@ -39,10 +40,45 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
@property (nullable, strong, nonatomic) NSLayoutConstraint *checkboxWidth; @property (nullable, strong, nonatomic) NSLayoutConstraint *checkboxWidth;
@property (nullable, strong, nonatomic) NSLayoutConstraint *checkboxHeight; @property (nullable, strong, nonatomic) NSLayoutConstraint *checkboxHeight;
@property (nonatomic) BOOL isRequired;
@property (nullable, strong, nonatomic) NSString *fieldKey;
@property (nullable, strong, nonatomic) DelegateObject *delegate;
@end @end
@implementation MVMCoreUICheckBox @implementation MVMCoreUICheckBox
#pragma mark - MVMCoreUIMoleculeViewProtocol
- (BOOL)needsToBeConstrained {
return YES;
}
- (UIStackViewAlignment)moleculeAlignment {
return UIStackViewAlignmentLeading;
}
- (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
[FormValidator setupValidationWithMolecule:self delegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol];
self.delegate = delegateObject;
self.fieldKey = [json stringForKey:KeyFieldKey];
self.isRequired = [json boolForKey:KeyRequired];
NSString *checkedColorHex = [json string:@"checkedColor"];
NSString *unCheckedColorHex = [json string:@"unCheckedColor"];
UIColor *checkedColor = checkedColorHex ? [UIColor mfGetColorForHex:checkedColorHex]: [UIColor blackColor];
UIColor *unCheckedColor = unCheckedColorHex ? [UIColor mfGetColorForHex:unCheckedColorHex]: [UIColor clearColor];
[self setupWithCheckedColor:checkedColor
unCheckColor:unCheckedColor
label:[json dict:KeyLabel]
delegateObject:delegateObject
additionalData: additionalData];
}
#pragma mark - convenient class methods #pragma mark - convenient class methods
+ (instancetype)mfCheckBox { + (instancetype)mfCheckBox {
@ -69,8 +105,33 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
return checkBox; return checkBox;
} }
#pragma mark - FormValidationProtocol
- (BOOL)isValidField {
if (self.isRequired) {
return self.isSelected;
}
return true;
}
- (nullable NSString *)formFieldName {
return self.fieldKey;
}
- (nullable id)formFieldValue {
return @(self.isSelected);
}
#pragma mark - inits #pragma mark - inits
- (instancetype)init {
self = [super init];
if (self) {
[self setupView];
}
return self;
}
- (instancetype)initWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor text:(NSString *)text { - (instancetype)initWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor text:(NSString *)text {
if (self = [super init]) { if (self = [super init]) {
[self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor text:text]; [self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor text:text];
@ -207,17 +268,25 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
} }
} }
- (void)setupWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor {
if (checkedColor) {
self.checkedColor = checkedColor;
}
if (unCheckedColor) {
self.unCheckedColor = unCheckedColor;
}
}
- (void)setupWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor text:(NSString *)text { - (void)setupWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor text:(NSString *)text {
[self setupView]; [self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor];
if (checkedColor) {
self.checkedColor = checkedColor;
}
if (unCheckedColor) {
self.unCheckedColor = unCheckedColor;
}
[self setDescriptionText:text]; [self setDescriptionText:text];
} }
- (void)setupWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor label:(NSDictionary *)labelJson delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
[self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor];
[self.descriptionLabel setWithJSON:labelJson delegateObject:delegateObject additionalData:additionalData];
}
- (void)updateView:(CGFloat)size { - (void)updateView:(CGFloat)size {
[MVMCoreDispatchUtility performBlockOnMainThread:^{ [MVMCoreDispatchUtility performBlockOnMainThread:^{
[self.descriptionLabel updateView:size]; [self.descriptionLabel updateView:size];
@ -254,7 +323,7 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
[self setSelected:selected animated:animated runBlock:YES]; [self setSelected:selected animated:animated runBlock:YES];
} }
- (void)setSelected:(BOOL)selected animated:(BOOL)animated runBlock:(BOOL)runBlock{ - (void)setSelected:(BOOL)selected animated:(BOOL)animated runBlock:(BOOL)runBlock {
[self addAccessibilityLabel:selected]; [self addAccessibilityLabel:selected];
self.isSelected = selected; self.isSelected = selected;
@ -272,6 +341,9 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
} completion:nil]; } completion:nil];
[self.checkMark updateCheckSelected:NO animated:animated]; [self.checkMark updateCheckSelected:NO animated:animated];
} }
FormValidator *formValidator = ((MVMCoreUIDelegateObject *)self.delegate).formValidationProtocol.formValidatorModel;
[formValidator enableByValidation];
} }
- (void)setColor:(nullable UIColor *)color forState:(UIControlState)state { - (void)setColor:(nullable UIColor *)color forState:(UIControlState)state {

View File

@ -44,13 +44,13 @@
// Pins all edges to its super. 0 constant // Pins all edges to its super. 0 constant
- (void)pinToSuperView; - (void)pinToSuperView;
// Add a view to be constrained in this view.
- (void)addConstrainedView:(nonnull UIView *)view;
// Resets all the constraints to default. // Resets all the constraints to default.
- (void)resetConstraints; - (void)resetConstraints;
// For setting up the view. // For setting up the view.
- (void)setupView; - (void)setupView;
// Add a view to be constrained in this view.
- (void)addConstrainedView:(nonnull UIView *)view;
@end @end

View File

@ -22,6 +22,6 @@ import Foundation
// The Field name key value pair for sending to server // The Field name key value pair for sending to server
@objc optional func formFieldName() -> String? @objc optional func formFieldName() -> String?
// The Feild value key value paid for sending to server // The Field value key value pair for sending to server
@objc optional func formFieldValue() -> String? @objc optional func formFieldValue() -> Any?
} }

View File

@ -32,7 +32,8 @@
@"standardFooter": StandardFooterView.class, @"standardFooter": StandardFooterView.class,
@"caretView": CaretView.class, @"caretView": CaretView.class,
@"caretButton": CaretButton.class, @"caretButton": CaretButton.class,
@"textField" : MFTextField.class @"textField" : MFTextField.class,
@"checkbox" : MVMCoreUICheckBox.class
} mutableCopy]; } mutableCopy];
}); });
return mapping; return mapping;

View File

@ -38,6 +38,9 @@ extern NSString * const KeyTextColor;
extern NSString * const KeyIsHidden; extern NSString * const KeyIsHidden;
extern NSString * const KeyIsOpaque; extern NSString * const KeyIsOpaque;
extern NSString * const KeyFieldKey;
extern NSString * const KeyRequired;
#pragma mark - Values #pragma mark - Values
extern NSString * const StringY; extern NSString * const StringY;

View File

@ -21,6 +21,8 @@ NSString * const KeyValue = @"value";
NSString * const KeyLabel = @"label"; NSString * const KeyLabel = @"label";
NSString * const KeyDisable = @"disable"; NSString * const KeyDisable = @"disable";
NSString * const KeyFieldName = @"fieldName"; NSString * const KeyFieldName = @"fieldName";
NSString * const KeyFieldKey = @"fieldKey";
NSString * const KeyRequired = @"required";
NSString * const KeyHideMainMenu = @"hideMainMenu"; NSString * const KeyHideMainMenu = @"hideMainMenu";
NSString * const KeyProgressPercent = @"progressPercent"; NSString * const KeyProgressPercent = @"progressPercent";
@ -37,6 +39,7 @@ NSString * const KeyTextColor = @"textColor";
NSString * const KeyIsHidden = @"isHidden"; NSString * const KeyIsHidden = @"isHidden";
NSString * const KeyIsOpaque = @"isOpaque"; NSString * const KeyIsOpaque = @"isOpaque";
#pragma mark - Values #pragma mark - Values
NSString * const StringY = @"Y"; NSString * const StringY = @"Y";