小编MrC*_*ujo的帖子

带 React-hook-form 的 Material UI (MUI) 日期选择器

我正在创建一个带有日期字段的表单。我正在使用 MUI 和 react-hook-form 进行验证。我尝试以两种不同的方式呈现该字段,但是在提交表单时我没有得到预期的值:

渲染1

使用控制器组件:

const [originalReleaseDate, setOriginalReleaseDate] = useState(null);

<Controller
                                name={"original_release_date"}
                                defaultValue={originalReleaseDate}
                                control={control}
                                render={({field}) =>
                                    <LocalizationProvider dateAdapter={AdapterDateFns}>
                                        <DatePicker
                                            label="Original Release Date"
                                            value={originalReleaseDate}
                                            onChange={(newValue) => {
                                                setOriginalReleaseDate(newValue);
                                            }}

                                            renderInput={(params) =>
                                                <TextField
                                                    {...params}
                                                />}
                                        />
                                    </LocalizationProvider>
                            }
                            />
Run Code Online (Sandbox Code Playgroud)

当我以这种方式渲染字段时,我会在提交表单后null得到。original_release_date

渲染2

{...register("reissue_release_date")}直接使用而不是react-hook-form 受控组件注册字段。

const [reissueReleaseDate, setReissueReleaseDate] = useState(null);

<LocalizationProvider dateAdapter={AdapterDateFns}>
                                <DatePicker
                                    label="Reissue Release Date"
                                    value={reissueReleaseDate}
                                    onChange={(newValue) => {
                                        setReissueReleaseDate(newValue);
                                    }}

                                    renderInput={(params) =>
                                        <TextField
                                            {...params}
                                            {...register("reissue_release_date")}
                                        />}
                                />
                            </LocalizationProvider>
Run Code Online (Sandbox Code Playgroud)

这种方法已经成功一半了。如果我手动输入日期,那么我将在提交时获取其值,但是如果我使用日期选择器,然后提交我得到的表单""

知道发生了什么事吗?

javascript reactjs material-ui react-hook-form

6
推荐指数
2
解决办法
2万
查看次数

Laravel:运行 phpunit 测试后删除了数据库表

每次运行测试时,我的所有数据库表(迁移表除外)都被删除,我必须再次运行迁移。例如,如果我有以下表格:

migrations
users
tableA
tableB
Run Code Online (Sandbox Code Playgroud)

运行后:

phpunit --filter user_can_view_a_record ViewRecordTest 测试/功能/ViewRecordTest.php

我的表被删除了,我最终只有迁移表。

我使用 MySQL 作为数据库,根据我设置的配置,测试正在内存中运行:

数据库.php

'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            //'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'database' => ':memory:',
            'prefix' => '',
        ],

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => …
Run Code Online (Sandbox Code Playgroud)

php mysql phpunit laravel

5
推荐指数
2
解决办法
4051
查看次数

Docker:无法从浏览器访问 SvelteKit 应用程序

我有一个 Svelte(带有 Sveltekit)应用程序,我刚刚对其进行了容器化。它构建正确,运行时没有错误,但我无法从浏览器访问它。我尝试访问http://localhost:5050/http://0.0.0.0:5050/但我得到:

\n
This page isn\xe2\x80\x99t working\nlocalhost didn\xe2\x80\x99t send any data.\nERR_EMPTY_RESPONSE\n
Run Code Online (Sandbox Code Playgroud)\n

这是Dockerfile我正在使用的:

\n
# Our Node base image\nFROM node:19-alpine\n\n# Set the Node environment to development to ensure all packages are installed\nENV NODE_ENV development\n\n# Change our current working directory\nWORKDIR /app\n\n# Copy over `package.json` and lock files to optimize the build process\nCOPY  package.json package-lock.json ./\n# Install Node modules\nRUN npm install\n\n# Copy over rest of the project files\nCOPY . .\n\nRUN npm run build\n\n# Expose port\nENV …
Run Code Online (Sandbox Code Playgroud)

node.js docker dockerfile svelte sveltekit

5
推荐指数
1
解决办法
1244
查看次数

Dockerized Sveltkit 应用程序:热重载不起作用

在 SO 社区的帮助下,我终于能够对我的 Sveltekit 应用程序进行 docker 化并从浏览器访问它(这最初是一个问题)。到目前为止一切顺利,但现在每次我执行代码更改时,我都需要重新构建和重新部署我的容器,这显然是不可接受的。热重载不起作用,我一直在尝试在网上找到的多种方法,但到目前为止没有一个起作用。

这是我的Dockerfile

FROM node:19-alpine

# Set the Node environment to development to ensure all packages are installed
ENV NODE_ENV development

# Change our current working directory
WORKDIR /app

# Copy over `package.json` and lock files to optimize the build process
COPY  package.json package-lock.json ./
# Install Node modules
RUN npm install

# Copy over rest of the project files
COPY . .

# Perhaps we need to build it for production, but …
Run Code Online (Sandbox Code Playgroud)

docker docker-compose svelte vite sveltekit

5
推荐指数
1
解决办法
2995
查看次数

OOP设计:抽象类设计与常规继承

为了好玩,我正在设计一个简单的系统来存储记录(黑胶唱片)数据和一些与记录有关的一般项目(袖子,记录清洁工等).

由于90%的数据将是黑胶唱片和其他10%的其他项目,我想把它们分成两类:记录和项目.请记住,尽管最后两者都是具有某些共同点的产品,如价格,数量等.

我怀疑是否应该创建一个抽象类,比如Item,以及两个扩展Item:Records和NonMusicalProducts的类.像这样的东西:

abstract class Item {

    static function getItemPrice($itemId, $type='record'){
        $result = 0;
        // query record table if type is record, otherwise query nonmusicalproduct table
        return $result;
    }

    abstract function getItemDetails();
}
Run Code Online (Sandbox Code Playgroud)

而记录:

class Record extends Item {
    static function getItemDetails($id) {
        // query DB and return record details
    }
}
Run Code Online (Sandbox Code Playgroud)

和NMProduct

class NMProduct extends Item {
    static function getItemDetails($id) {
        // query DB and return NMProduct details
    }
}
Run Code Online (Sandbox Code Playgroud)

将NMProduct和Record中的两个方法定义为静态可以吗?我并不总是从一个对象访问该方法.

另一个选项是只有一个Item类和一个可以从item继承的Record类,但是我已经到了一个看起来不正确的点,特别是在尝试获取细节时:

class Item {
   function getItemDetails($id, $type){
        if …
Run Code Online (Sandbox Code Playgroud)

oop design-patterns dry object-oriented-analysis

3
推荐指数
1
解决办法
189
查看次数

Sveltekit 不会拦截 handleFetch 挂钩中的 fetch 调用

我最近handleFetch在 Sveltekit 中发现了这个钩子。现在我试图用它来拦截对我的后端的调用(用 Go 编写),但似乎不起作用(除非我错过了一些东西)。

文档内容如下:

此函数允许您修改(或替换)在服务器上运行的加载或操作函数内(或预渲染期间)发生的获取请求。

我有src\hooks.server.js

/** @type {import('@sveltejs/kit').HandleFetch} */
export async function handleFetch({ request, fetch }) {
    console.log("HERE IN --------> HANDLE FETCH HOOK")

    return fetch(request);
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我只是想通过在终端上打印消息来确保调用挂钩。

我有一个load函数src\routes\records\+page.server.js

export async function load() {
    console.log("HERE IN LOAD")
    // const records = await getAllRecords(1, 10);
    const response = await fetch(`http://127.0.0.1:8080/api/v1/records?page=1&per_page=2`);
    const records = await response.json();
    console.log(await records);
    return records;
}
Run Code Online (Sandbox Code Playgroud)

尽管我看到HERE IN LOAD消息和正在打印的响应,但我从未看到指示钩子被击中的消息。

我缺少什么?

谢谢

javascript fetch-api svelte svelte-3 sveltekit

3
推荐指数
1
解决办法
1179
查看次数

将PNG Base-64字符串转换为TIFF Base-64字符串

我正在使用一个返回PNG编码的base64字符串的插件,我无法更改它,我必须使用它,但我真正需要的是tiff编码值(base-64).有办法做到这一点吗?

我试图创建一个画布,加载png base64然后使用toDataURL('image/tiff')但经过一些研究后,我发现tiff不支持输出toDataURL().

有什么建议?

javascript html5 base64 png tiff

2
推荐指数
1
解决办法
2321
查看次数

找不到 Jinja 嵌套模板

我的烧瓶项目中有以下结构:

app
   -app
     -static
     -templates
       -layouts
         footer.html
         header.html
         main.html
       search.html
     __init__.py
     app.py
     MANIFEST.in
     setup.py
Run Code Online (Sandbox Code Playgroud)

在应用程序.py中:

@app.route('/search')
def show_search_form():
    return render_template('search.html')
Run Code Online (Sandbox Code Playgroud)

搜索.html:

{% extends "layouts/main.html" %}

{% block body %}

Test

{% endblock %}
Run Code Online (Sandbox Code Playgroud)

主要.html

{% include 'header.html' %}

{% block content %}

{% endblock %}

{% include 'footer.html' %}
Run Code Online (Sandbox Code Playgroud)

header.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>App</title>
</head>
<body>
Run Code Online (Sandbox Code Playgroud)

页脚.html

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我将 main.html 扩展为 search.html 并使用(在本例中)“Test”作为要注入到正文块中的内容。但它不起作用,我收到以下错误:

jinja2.exceptions.TemplateNotFound: header.html
Run Code Online (Sandbox Code Playgroud)

代码有什么问题吗?

jinja2 flask python-3.x

2
推荐指数
1
解决办法
2812
查看次数

Laravel:验证大于零的数字是失败的

我要验证价格字段需要大于零(0.01有效),所以我有以下验证:

$request->validate([
            'product_price' => 'required|numeric|gt:0',
        ]);
Run Code Online (Sandbox Code Playgroud)

问题是,当我在'product_price'字段中输入一个字符串时,我收到一个错误:

InvalidArgumentException比较下的值必须是相同的类型

这是为什么?我的意思是,在检查它是否> 0之前,我正在检查它应该是数字

php validation laravel laravel-validation

2
推荐指数
2
解决办法
8527
查看次数

Laravel 6 重写 FormRequest 的 failedValidation 方法时出现自定义验证错误“类不存在”

我创建了一个自定义验证类,位于app\Http\Requests

<?php

namespace App\Http\Requests;

use App\Http\Requests\BaseFormRequest;

class RegisterUserRequest extends BaseFormRequest
{
    protected static $NEEDS_AUTHORIZATION = false;

    protected static $FORM_RULES = [
        'first_name'              => 'required|string|max:80',
        'last_name'               => 'required|string|max:80',
        'email'                   => 'required|unique:users|email',
        'password'                => 'required|string|min:6|confirmed',
        'terms_conditions'        => 'accepted'
    ];

}
Run Code Online (Sandbox Code Playgroud)

BaseFormRequest并在同一目录中扩展:

<?php 

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Validator;
use Illuminate\Validation\ValidationException;
use Illuminate\Http\Exceptions\HttpResponseException;
//use Illuminate\Http\Request;

abstract class BaseFormRequest extends FormRequest 
{
    protected static $NEEDS_AUTHORIZATION = true;
    protected static $FORM_RULES          = [];
    protected static $ERROR_MESSAGES      = [];

    /**
     * Determine if …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-validation laravel-response laravel-6

2
推荐指数
1
解决办法
5662
查看次数

调整iFrame内容大小无法在移动设备上使用

我有以下HTML页面:

<html>
<head>
<style>
    #dummy-block {      
        display: block;
        position: relative;
        margin-top: 70px;
        width: 100%;
        height: 70px;
        border: 2px solid red;
    }

    .paragraph {
        display: block;
        position: relative;
        margin-top: 50px;
        width: 100%;
    }
</style>
</head>

<body>

<h1>iFrame Test</h1>
<iframe seamles name="inlineframe" src="About.html" frameborder="1" scrolling="auto" width="100%" height="500px" marginwidth="5" marginheight="5">
</iframe>


<div id="dummy-block">
</div>

<div class="paragraph">
    <h3>Test Paragraph</h3>
    <p>
        Li Europan lingues es membres del sam familie. Lor separat existentie es un myth. Por   
        scientie, musica, sport etc, litot Europa usa li sam …
Run Code Online (Sandbox Code Playgroud)

html iframe twitter-bootstrap

1
推荐指数
1
解决办法
3119
查看次数

Laravel 6:调用未定义的方法 App\\User::createToken()

我正在尝试通过以下方式生成令牌以对我的控制器中的用户进行身份验证:

namespace App\Http\Controllers\API;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use App\Models\User;

class AuthController extends Controller
{
    public function login()
    {
        if (Auth::attempt(['email' => request('email'), 'password' => request('password')])) {
            $user = Auth::user();


            $success['token'] = $user->createToken('myApp')->accessToken;
            dd($success['token']);

        }
    }
Run Code Online (Sandbox Code Playgroud)

目前,我只是想打印出令牌。这是我的用户模型:

<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
//use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Hash;
use Laravel\Passport\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, Notifiable;

    const USER_FIRST_NAME_FIELD        = "first_name";
    const USER_LAST_NAME_FIELD         = "last_name";
    const USER_PREFERRED_NAME_FIELD    = "preferred_name";
    const USER_EMAIL_FIELD             = "email";
    const …
Run Code Online (Sandbox Code Playgroud)

php laravel eloquent laravel-passport laravel-authentication

1
推荐指数
1
解决办法
2万
查看次数