-
Notifications
You must be signed in to change notification settings - Fork 132
feat(FwbInput): Add direct error message support #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
radudiaconu0
wants to merge
4
commits into
themesberg:main
Choose a base branch
from
radudiaconu0:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
docs/components/input/examples/FwbInputExampleErrorMessage.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<template> | ||
<div class="vp-raw"> | ||
<h3 class="mb-3 text-lg font-medium text-gray-900 dark:text-white">Error Messages Examples</h3> | ||
|
||
<!-- Direct error message prop --> | ||
<div class="mb-4"> | ||
<fwb-input | ||
v-model="username" | ||
label="Username" | ||
placeholder="Enter your username" | ||
validation-status="error" | ||
error-message="This username is already taken" | ||
/> | ||
</div> | ||
|
||
<!-- Direct success message prop --> | ||
<div class="mb-4"> | ||
<fwb-input | ||
v-model="email" | ||
label="Email" | ||
placeholder="Enter your email" | ||
validation-status="success" | ||
success-message="Email format is valid" | ||
/> | ||
</div> | ||
|
||
<!-- Form validation example --> | ||
<div class="mb-4"> | ||
<fwb-input | ||
v-model="password" | ||
type="password" | ||
label="Password" | ||
placeholder="Enter your password" | ||
:validation-status="passwordValidation.status" | ||
:error-message="passwordValidation.message" | ||
/> | ||
</div> | ||
|
||
<!-- Toggle hideDetails demo --> | ||
<div class="mb-4 flex items-center"> | ||
<fwb-checkbox | ||
v-model="hideDetails" | ||
label="Hide error details" | ||
/> | ||
</div> | ||
|
||
<!-- Example with hideDetails --> | ||
<div class="mb-4"> | ||
<fwb-input | ||
v-model="phone" | ||
label="Phone Number" | ||
placeholder="Enter your phone number" | ||
validation-status="error" | ||
error-message="Please enter a valid phone number" | ||
:hide-details="hideDetails" | ||
/> | ||
</div> | ||
|
||
<!-- Comparison: prop vs slot approach --> | ||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4"> | ||
<div> | ||
<h4 class="mb-2 text-base font-medium text-gray-900 dark:text-white">Using error-message prop</h4> | ||
<fwb-input | ||
v-model="address" | ||
label="Address" | ||
placeholder="Enter your address" | ||
validation-status="error" | ||
error-message="Please enter your full address" | ||
/> | ||
</div> | ||
|
||
<div> | ||
<h4 class="mb-2 text-base font-medium text-gray-900 dark:text-white">Using validation slot</h4> | ||
<fwb-input | ||
v-model="address" | ||
label="Address" | ||
placeholder="Enter your address" | ||
validation-status="error" | ||
> | ||
<template #validationMessage> | ||
<div class="flex items-center"> | ||
<svg class="w-4 h-4 mr-1.5 text-red-500" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> | ||
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"></path> | ||
</svg> | ||
Please enter your full address | ||
</div> | ||
</template> | ||
</fwb-input> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { computed, ref } from 'vue' | ||
|
||
import { FwbCheckbox, FwbInput } from '../../../../src/index' | ||
import { validationStatusMap } from '../../../../src/components/FwbInput/types' | ||
|
||
// Form values | ||
const username = ref('') | ||
const email = ref('') | ||
const password = ref('') | ||
const phone = ref('') | ||
const address = ref('') | ||
|
||
// UI state | ||
const hideDetails = ref(false) | ||
|
||
// Form validation | ||
const passwordValidation = computed(() => { | ||
if (!password.value) { | ||
return { | ||
status: validationStatusMap.Error, | ||
message: 'Password is required' | ||
} | ||
} | ||
|
||
if (password.value.length < 8) { | ||
return { | ||
status: validationStatusMap.Error, | ||
message: 'Password must be at least 8 characters' | ||
} | ||
} | ||
|
||
return { | ||
status: validationStatusMap.Success, | ||
message: 'Password meets requirements' | ||
} | ||
}) | ||
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not imported and results in an error:
[Vue warn]: Failed to resolve component: fwb-input-example-error-message