Skip to content

Commit

Permalink
Merge branch 'hotfix/1.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Aug 30, 2021
2 parents 42c8533 + d360dea commit 0a160ec
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 325 deletions.
4 changes: 0 additions & 4 deletions Example/FieldValidatorSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
A0533DC624EAEF9E009C784B /* FieldValidator+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0533DC524EAEF9E009C784B /* FieldValidator+Helpers.swift */; };
A059CE6F26DB8EA9007002F2 /* FieldValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = A059CE6E26DB8EA9007002F2 /* FieldValidator.swift */; };
A059CE7126DB925E007002F2 /* FormWithValidatorV1.swift in Sources */ = {isa = PBXBuildFile; fileRef = A059CE7026DB925E007002F2 /* FormWithValidatorV1.swift */; };
A059CE7326DB9272007002F2 /* FormWithValidatorV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = A059CE7226DB9272007002F2 /* FormWithValidatorV2.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -35,7 +34,6 @@
A0533DC524EAEF9E009C784B /* FieldValidator+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FieldValidator+Helpers.swift"; sourceTree = "<group>"; };
A059CE6E26DB8EA9007002F2 /* FieldValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FieldValidator.swift; path = ../Sources/FieldValidatorLibrary/FieldValidator.swift; sourceTree = "<group>"; };
A059CE7026DB925E007002F2 /* FormWithValidatorV1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormWithValidatorV1.swift; sourceTree = "<group>"; };
A059CE7226DB9272007002F2 /* FormWithValidatorV2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormWithValidatorV2.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -80,7 +78,6 @@
5F4486B523568D18007FA51F /* Info.plist */,
5F4486AF23568D18007FA51F /* Preview Content */,
A059CE7026DB925E007002F2 /* FormWithValidatorV1.swift */,
A059CE7226DB9272007002F2 /* FormWithValidatorV2.swift */,
);
path = FieldValidatorSample;
sourceTree = "<group>";
Expand Down Expand Up @@ -169,7 +166,6 @@
A059CE7126DB925E007002F2 /* FormWithValidatorV1.swift in Sources */,
A0533DC624EAEF9E009C784B /* FieldValidator+Helpers.swift in Sources */,
A017662124F3BB5A00E04DE3 /* String+Email.swift in Sources */,
A059CE7326DB9272007002F2 /* FormWithValidatorV2.swift in Sources */,
A047652023DDF687005B8547 /* PasswordToggleField.swift in Sources */,
5F4486AA23568D17007FA51F /* SceneDelegate.swift in Sources */,
5F4486AC23568D17007FA51F /* ContentView.swift in Sources */,
Expand Down
8 changes: 1 addition & 7 deletions Example/FieldValidatorSample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@ struct ContentView : View {

NavigationView {
TabView {
FormWithValidatorV2()
.environmentObject( DataItem() )
.tabItem {
Label("Form validator v2", systemImage: "list.dash")
}

FormWithValidatorV1()
.environmentObject( DataItem() )
.tabItem {
Label("Form validator v1", systemImage: "square.and.pencil")
Label("Form validator", systemImage: "square.and.pencil")
}
}
.navigationBarTitle( Text( "FieldValidator Samples" ), displayMode: .inline )
Expand Down
155 changes: 0 additions & 155 deletions Example/FieldValidatorSample/FormWithValidatorV2.swift

This file was deleted.

4 changes: 2 additions & 2 deletions FieldValidatorLibrary.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
#

spec.name = "FieldValidatorLibrary"
spec.version = "2.0.0"
spec.version = "1.4.1"
spec.summary = "SwiftUI library supporting 'Form Validation'"

# This description is used to generate tags and improve search results.
Expand Down Expand Up @@ -81,7 +81,7 @@ Pod::Spec.new do |spec|
# Supports git, hg, bzr, svn and HTTP.
#

spec.source = { :git => "https://github.com/bsorrentino/swiftui-fieldvalidator.git", :tag => "v2.0.0" }
spec.source = { :git => "https://github.com/bsorrentino/swiftui-fieldvalidator.git", :tag => "v1.4.1" }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand Down
96 changes: 1 addition & 95 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,105 +19,11 @@ This Library is compatible with [Cocoapods](https://cocoapods.org).

In your **Podfile** add
```
pod 'FieldValidatorLibrary', '~> 2.0.0'
pod 'FieldValidatorLibrary', '~> 1.4.1'
```

## Sample

### Version 2

```swift

// validation closure where ‘v’ is the current value
func usernameValididator( _ v:String ) -> String? {
if( v.isEmpty ) {
return "email cannot be empty"
}
if( !v.isEmail() ) {
return "email is not in correct format"
}

return nil
}

// validation closure where ‘v’ is the current value
func passwordValididator( _ v:String ) -> String? {
if( v.isEmpty ) {
return "password cannot be empty"
}
return nil
}

struct FormWithValidatorV2 : View {
@EnvironmentObject var item:DataItem// data model reference

@StateObject var username = FieldValidator2( "", debounceInMills: 700, validator: usernameValididator )
@StateObject var password = FieldValidator2( "", validator: passwordValididator)

func usernameView() -> some View {
TextField( "give me the email",
text: $username.value,
onCommit: submit)
.autocapitalization(.none)
.padding( .bottom, 25 )
.overlay( ValidatorMessageInline( message: username.errorMessageOrNilAtBeginning ), alignment: .bottom)
.onAppear {
username.doValidate()
}
.onChange(of: username.value) {
item.username = $0
}
}

func passwordToggleView() -> some View {
SecureField( "give me the password", text: $password.value )
.autocapitalization(.none)
.padding( .bottom, 25 )
.overlay( ValidatorMessageInline( message: password.errorMessage ),alignment: .bottom)
.onAppear {
password.doValidate()
}
.onChange(of: password.value) {
item.password = $0
}
}

var isValid:Bool {
password.valid && username.valid
}

func submit() {
if( isValid ) {
print( "submit:\nusername:\(self.username.value)\npassword:\(self.password.value)")
}
}

var body: some View {
NavigationView {
Form {
Section(header: Text("Credentials")) {
usernameView()
passwordToggleView()
} // end of section
Section {
HStack {
Spacer()
Button( "Submit" ) { self.submit() }
// enable button only if username and password are valid
.disabled( !self.isValid )
Spacer()
}
} // end of section
} // end of form
.navigationBarTitle( Text( "Sample Form" ), displayMode: .inline )
} // NavigationView
}
}

```

### Version 1 (Deprecated)

```swift

struct FormWithValidatorV1 : View {
Expand Down
Loading

0 comments on commit 0a160ec

Please sign in to comment.