webcito/bs-prompt 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webcito/bs-prompt

Composer 安装命令:

composer require webcito/bs-prompt

包简介

description

README 文档

README

bsPrompt is a jQuery plugin for Bootstrap 5 that replaces window.prompt with a Bootstrap modal dialog.

Installation

<link rel="stylesheet" href="vendor/twbs/bootstrap/dist/css/bootstrap.min.css">
<script src="vendor/components/jquery/jquery.min.js"></script>
<script src="vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="dist/bs-prompt.js"></script>

Usage

$.bsPrompt() is asynchronous because Bootstrap modals cannot block JavaScript execution like the native browser prompt. The returned jQuery Promise is the primary API for reading the result.

$.bsPrompt({
  title: 'Enter a name',
  message: 'What should the new item be called?',
  label: 'Name',
  type: 'text',
  required: true
}).then(function (value) {
  if (value === null) {
    return;
  }

  console.log(value);
});

Short form:

$.bsPrompt('Please enter a name', 'Default value').then(function (value) {
  console.log(value);
});

Handling Confirm

Confirmed prompts resolve with the submitted string.

$.bsPrompt({
  title: 'Password',
  label: 'Password',
  type: 'password',
  required: true
}).then(function (value) {
  if (value === null) {
    return;
  }

  submitPassword(value);
});

Handling Cancel

Cancelled prompts resolve with null.

$.bsPrompt({
  title: 'Delete item',
  message: 'Type the item name to continue.',
  required: true
}).then(function (value) {
  if (value === null) {
    console.log('The prompt was cancelled.');
    return;
  }

  deleteItem(value);
});

Optional Callbacks

Use onConfirm and onCancel only for side effects such as logging, analytics, or small UI updates. Do not use them as the main way to read the prompt result.

$.bsPrompt({
  title: 'Enter a name',
  required: true,
  onConfirm: function (value) {
    console.log('confirmed', value);
  },
  onCancel: function () {
    console.log('cancelled');
  }
}).then(function (value) {
  console.log('result', value);
});

Options

Option Default Description
title 'Input required' Modal title
message '' Text above the input field
label null Input label
value '' Initial value
type 'text' Input type: text, password, email, number, url, tel, date, time, textarea, etc.
required false Prevents empty submissions
validate null Custom validation callback. Return true, false, or an error message string
invalidFeedback 'Please enter a value.' Error message for empty values
okText 'OK' OK button text
cancelText 'Cancel' Cancel button text
onConfirm null Optional side-effect callback after a valid confirmation
onCancel null Optional side-effect callback after cancellation
attributes {} Additional HTML attributes, for example { maxlength: 80 }

Default Texts

$.bsPrompt.setDefaults({
  title: 'Please provide input',
  okText: 'Continue',
  cancelText: 'Dismiss',
  invalidFeedback: 'This field is required.'
});

Replacing Native Prompt

replaceNative() overwrites window.prompt. After installing it, calls to prompt() open a Bootstrap modal instead of the browser's native blocking prompt.

$.bsPrompt.replaceNative({ required: true });

prompt('Name?', 'Max').then(function (value) {
  console.log(value);
});

This is intentionally not a drop-in replacement for synchronous code. Native browser prompts block JavaScript and return a string immediately; Bootstrap modals are asynchronous and return a jQuery Promise.

This native code cannot be preserved unchanged:

var value = prompt('Name?');
console.log(value);

Use the Promise result instead:

prompt('Name?').then(function (value) {
  if (value === null) {
    return;
  }

  console.log(value);
});

Restore the original browser prompt:

$.bsPrompt.restoreNative();

webcito/bs-prompt 适用场景与选型建议

webcito/bs-prompt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 06 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 webcito/bs-prompt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 webcito/bs-prompt 我们能提供哪些服务?
定制开发 / 二次开发

基于 webcito/bs-prompt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2026-06-02