Hello everyone,
The thing that I want to do is a dynamic searchbar in symfony with ajax.
I already have a filter system and i want the searchbar work with it.
I’m trying to do that in ajax + symfony 6.2.
My PHP version is 8.1.10.
the code in my controller est*: https://sharemycode.io/c/f4341e6
the code in my twig est*: https://sharemycode.io/c/879139d
the code in my js*: https://sharemycode.io/c/1615e4d
the code in my form: https://sharemycode.io/c/aa9a8d0
forthe Repo*: https://sharemycode.io/c/d29c882
The probleme here is that the search don’t refresh when i write in the input (nothing happen).
Maybe the problem is from the javascript ?
Thanks for reading and for ur help !I tried to vardump the result in controller, i have it but this is only when i send the form searchbar ..
Category: javascript
Category Added in a WPeMatico Campaign
VNC view only mode on webpage
I have a PC with a VNC server running, and I need to display the screen of that PC on a webpage; however, the VNC server is configured in “view only” mode. So is it possible to show that screen on a webpage in a ?
I am trying to display a screen on a website through VNC.
How do I stop Formik blurring on state change in hook?
Here is a nice minimum reproducible example for my problem:
import React from 'react';
import { render } from 'react-dom';
import { Formik, Form, Field } from 'formik';
const App = () => {
const [imgSrc, setImgSrc] = React.useState('');
return <>
<Formik
initialValues={{
'imgSrc': '',
}}
>
<Form>
<img src={imgSrc} alt="whatever you typed in" />
<Field
name="imgSrc"
onChange={e => setImgSrc(e.target.value)}
/>
</Form>
</Formik>
</>;
}
render(<App />, document.getElementById('root'));
Whenever I update imgSrc (the field with that name attribute) then Formik seems to reset and blur the input… This is very annoying!
How can I get Formik to stop doing this?
I’ve also provided a nice codesandbox.
[Unhandled promise rejection: TypeError: undefined is not an object (evaluating ‘item.subcategories.length’)]
I have a react native app. And I try to check if a array of objects has length 0.
So I have this:
export const SubCategoryScreen = ({ route, navigation }) => {
const [subCatgoryList, setSubCategoryList] = useState([]);
const [isLoading, setLoading] = useState(true);
useEffect(() => {
fetchSubCategoryData(route.params.subcategories).then((data) => {
if (data.animals.length > 0) {
setSubCategoryList(data.animals);
setLoading(false);
} else {
setSubCategoryList(data.subcategories);
setLoading(false);
}
});
}, [route]);
return (
<SafeArea>
{isLoading && (
<LoadingContainer>
<ActivityIndicator animating={true} color={MD2Colors.green200} />
</LoadingContainer>
)}
<CategoryList
data={subCatgoryList}
renderItem={({ item, index }) => {
console.log(item);
return (
<TouchableOpacity
onPress={() => navigation.navigate("groepen", { subcategories: item.id })}
disabled={
isLoading || (item.subcategories.length === 0 && item.animals.length === 0)
}>
<Spacer position="bottom" size="large">
<SubCategoryInfoCard subcategories={item} />
</Spacer>
</TouchableOpacity>
);
}}
keyExtractor={(item) => item.id}
/>
</SafeArea>
);
};
And the error occuried on this part:
disabled={isLoading || (item.subcategories.length === 0 && item.animals.length === 0)}
and the api call looks like:
{
"id": 6,
"name": "haviken",
"description": "haviken",
"legislation": "",
"review": "",
"eaza": "",
"images": "http://192.168.1.68:8000/media/photos/categories/peregrine_falcon.jpg",
"animals": [],
"subcategories": [],
"category": "http://192.168.1.68:8000/api/categories/3/"
}
So it seems that both: animals and subcatgories are empty.
Question: How to check if array of objects is empty?
Trouble Showing Image on page load HTML JavaScript CSS
HTML
<!--Slide Show----------------------------->
<div class="slide-show-page" id="media-section">
<div class="container">
<div class="mySlides">
<div class="numbertext">1 / 6</div>
<img src="images/img_woods_wide.jpg" style="width:100%">
</div>
<div class="mySlides">
<div class="numbertext">2 / 6</div>
<img src="images/img_5terre_wide.jpg" style="width:100%" />
</div>
<div class="mySlides">
<div class="numbertext">3 / 6</div>
<img src="images/img_mountains_wide.jpg" style="width:100%" />
</div>
<div class="mySlides">
<div class="numbertext">4 / 6</div>
<img src="images/img_lights_wide.jpg" style="width:100%" />
</div>
<div class="mySlides">
<div class="numbertext">5 / 6</div>
<img src="images/grassymountain.jpg" style="width:100%" />
</div>
<div class="mySlides">
<div class="numbertext">6 / 6</div>
<img src="images/img_snow_wide.jpg" style="width:100%" />
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
<div class="caption-container">
<p id="caption"></p>
</div>
<div class="row">
<div class="column">
<img class="demo cursor" src="images/img_woods_wide.jpg" style="width:100%" onclick="currentSlide(1)" alt="The Woods">
</div>
<div class="column">
<img class="demo cursor" src="images/img_5terre_wide.jpg" style="width:100%" onclick="currentSlide(2)" alt="Cinque Terre">
</div>
<div class="column">
<img class="demo cursor" src="images/img_mountains_wide.jpg" style="width:100%" onclick="currentSlide(3)" alt="Mountains and fjords">
</div>
<div class="column">
<img class="demo cursor" src="images/img_lights_wide.jpg" style="width:100%" onclick="currentSlide(4)" alt="Northern Lights">
</div>
<div class="column">
<img class="demo cursor" src="images/grassymountain.jpg" style="width:100%" onclick="currentSlide(5)" alt="Nature and sunrise">
</div>
<div class="column">
<img class="demo cursor" src="images/img_snow_wide.jpg" style="width:100%" onclick="currentSlide(6)" alt="Snowy Mountains">
</div>
</div>
</div>
</div>
SCSS
.slide-show-page {
* {
box-sizing: border-box;
}
background-color: $gallery-background;
height: $viewport-height;
width: $viewport-width;
color: $black-text;
h2 {
padding-top: 16vh;
padding-bottom: 2vh;
color: $green-text;
position: static;
}
img {
vertical-align: middle;
}
/* Position the image container (needed to position the left and right arrows) */
.container {
position: relative;
}
/* Hide the images by default */
.mySlides {
display: none;
}
/* Add a pointer when hovering over the thumbnail images */
.cursor {
cursor: pointer;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 40%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* Container for image text */
.caption-container {
text-align: center;
background-color: #222;
padding: 2px 16px;
color: white;
}
.row:after {
content: "";
display: table;
clear: both;
}
/* Six columns side by side */
.column {
float: left;
width: 16.66%;
}
/* Add a transparency effect for thumnbail images */
.demo {
opacity: 0.6;
}
.active,
.demo:hover {
opacity: 1;
}
}
.js
let slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
let i;
let slides = document.getElementsByClassName("mySlides");
let dots = document.getElementsByClassName("demo");
let captionText = document.getElementById("caption");
if (n > slides.length) { slideIndex = 1 }
if (n < 1) { slideIndex = slides.length }
for (i = 1; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " active";
captionText.innerHTML = dots[slideIndex - 1].alt;
}
Using visual studios community and a w3 slide show help tutorial i Cannot get the first image to load when page loads, it has somthing to do with .mySlides Display: none however the .JS file is not setting the display to block when I debug the code as it did in the W3 tutorial
the picture does div does display when one of the icons are clicked not sure if my JS is getting ran til the onclick is used from the icon setting the current slide
showSlides(slideIndex); is supposed to do this however i tried (function {…(.js)}();
https://www.w3schools.com/howto/howto_js_slideshow_gallery.asp
Any ideas?
issue with the Owl carousel because of an incorrect linking of something?
I am attempting to incorporate the Owl Carousel into my latest project, but I seem to be encountering some difficulties with it. At this point, only the HTML and CSS seem to be functioning correctly. I believe I may be making a mistake with the Script, but I am unsure of what exactly I am doing wrong. Can someone kindly assist me and examine my code to identify where I am going wrong?
#work_process {
background-color: #f9f9f9;
padding: 50px 0;
}
#work_process h5 {
font-size: 18px;
color: #555;
}
#work_process h3 {
font-size: 36px;
font-weight: bold;
margin-top: 20px;
margin-bottom: 50px;
}
.work_box {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
padding: 20px;
text-align: center;
}
.work_box h6 {
font-size: 18px;
margin-top: 30px;
margin-bottom: 20px;
font-weight: bold;
color: #333;
}
.work_box p {
font-size: 14px;
color: #555;
line-height: 1.5;
margin-bottom: 30px;
}
.step_box {
width: 70px;
height: 70px;
border-radius: 50%;
background-color: #555;
color: #fff;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto;
margin-bottom: 30px;
}
.step_box h4 {
font-size: 24px;
font-weight: bold;
margin: 0;
}
.owl-carousel .owl-nav button {
color: #555;
font-size: 24px;
position: absolute;
top: 50%;
transform: translateY(-50%);
z-index: 1;
background-color: transparent;
border: none;
outline: none;
cursor: pointer;
}
.owl-carousel .owl-nav button.owl-prev {
left: 0;
}
.owl-carousel .owl-nav button.owl-next {
right: 0;
}
.owl-carousel .owl-dots {
text-align: center;
margin-top: 50px;
}
.owl-carousel .owl-dots button {
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #ccc;
margin: 0 5px;
border: none;
outline: none;
cursor: pointer;
transition: all 0.3s;
}
.owl-carousel .owl-dots button.active {
background-color: #555;
}
//css
#work_process {
background-color: #f9f9f9;
padding: 50px 0;
}
#work_process h5 {
font-size: 18px;
color: #555;
}
#work_process h3 {
font-size: 36px;
font-weight: bold;
margin-top: 20px;
margin-bottom: 50px;
}
.work_box {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
padding: 20px;
text-align: center;
}
.work_box h6 {
font-size: 18px;
margin-top: 30px;
margin-bottom: 20px;
font-weight: bold;
color: #333;
}
.work_box p {
font-size: 14px;
color: #555;
line-height: 1.5;
margin-bottom: 30px;
}
.step_box {
width: 70px;
height: 70px;
border-radius: 50%;
background-color: #555;
color: #fff;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto;
margin-bottom: 30px;
}
.step_box h4 {
font-size: 24px;
font-weight: bold;
margin: 0;
}
.owl-carousel .owl-nav button {
color: #555;
font-size: 24px;
position: absolute;
top: 50%;
transform: translateY(-50%);
z-index: 1;
background-color: transparent;
border: none;
outline: none;
cursor: pointer;
}
.owl-carousel .owl-nav button.owl-prev {
left: 0;
}
.owl-carousel .owl-nav button.owl-next {
right: 0;
}
.owl-carousel .owl-dots {
text-align: center;
margin-top: 50px;
}
.owl-carousel .owl-dots button {
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #ccc;
margin: 0 5px;
border: none;
outline: none;
cursor: pointer;
transition: all 0.3s;
}
.owl-carousel .owl-dots button.active {
background-color: #555;
}
Slide controls (prev, next) not responding to clicks
I am having difficulty getting the navigation controls (previous and next) on an HTML slide to function properly, allowing the user to click and move through the other slides. I have attempted to implement this feature, but my efforts have been unsuccessful. You can view my unsuccessful attempt at the following link:
`https://codepen.io/MrJack-Mcfreder/pen/LYJQbeZ`
To clarify, This is a Fiverr slideshow, and It includes navigation controls that allow the user to move forward and backward through the slides. However, despite my best efforts, these controls are not functioning as intended.
Javascript, I want my elements to only move in a specific path
I’m working on an app but there’s a background with dots that determines where my elements can be placed and moved. I illustrated what i want in Adobe XD.
The path of the red circle is what i want to achieve, the blue square is what I don’t want because it’s just placed anywhere.
So far, I created a html canvas, where i drew this dots with a for loop. I’ve been thinking about creating invisible areas but I don’t know what to implement in js.
Is there a way to create a date input field that can allow for 00 for DD / MM inputs if values are unknown?
I’ve been trying to create a datepicker field that can allow for certain invalid date ranges i.e. 00 if the DD or MM for a date of birth is of an unknown value. The base UI components that I am using are MUI’s DatePicker and MUI’s FilledInput / TextField. For instance, a person with a birth date of March 1943 should be able to input their DOB as 00 / 03 / 1943 on the frontend.
So far, as far as I understand and read, this can’t be done with input fields of ‘type = “date”‘ as 00 would be autocorrected to 01.
As a continuation to the above question, I have used a standard text field instead with masking, such as react-imask library and it works (sort of haphazardly). A key feature that I am still missing if I were to use a text field is that my text input is not split neatly into each date block (Day or Month or Year) like the MUI example attached
enter image description here
My questions are:
- Is there a way to build such a custom datepicker using date inputs?
- If not, would using a text field be a suitable solution to the problem?
- How can I get the described behavior to get my blocks of text to correspond to each date block?
Npm run dev not showing Event line on cmd and localhost stuck on loading (I am new to this so any help will be appreciated)
MongoDB: More Performant Way to Update an Array of Subdocuments from an Array of Values?
I’ve searched the forums and the mongodb docs but I’m still struggling with this one. I have an Article model, with a property called triangle_key which is an array of objects:
const articleSchema = new mongoose.Schema({
triangle_key: [{
token: Number,
unique_beer: String,
unique_cup: String,
}],
})
Users can submit an array of triangle_keys via a form. This array gets sent to the server on req.body.key and looks like this:
[
{token: "1", unique_beer: "blue", unique_cup: "B"},
{token: "2", unique_beer: "yellow", unique_cup: "A"},
...
]
What is the best way to update every triangle_key in the Article with its corresponding value in req.body.key? In other words, if a user submits four triangle_keys with tokens 1, 2, 3 and 4, I would like to update the triangle_keys with token 1, 2, 3 and 4 in the Article to match. If the user submits a triangle_key with a token that doesn’t currently exist in Article.triangle_key, then I want to add it to Article.triangle_key.
I currently solve this by looping through the array in req.body.key and querying the Article every iteration… The below code works, but is very slow.
// add or update each token/unique_beer pair to the article key
for (const inputSet of req.body.key) {
const updateResults = await Article.updateOne(
{ _id: req.params.article_id },
{ $set:
{
"triangle_key.$[elem].token": inputSet.token,
"triangle_key.$[elem].unique_beer": inputSet.unique_beer,
"triangle_key.$[elem].unique_cup": inputSet.unique_cup,
}
},
{
arrayFilters: [ { "elem.token": { $eq: inputSet.token } } ]
}
);
// if it couldn't update it (didn't find a match), then push a new one.
if (updateResults.modifiedCount === 0) {
await Article.updateOne(
{ _id: req.params.article_id },
{ $push:
{
triangle_key:
{
token: inputSet.token,
unique_beer: inputSet.unique_beer,
unique_cup: inputSet.unique_cup,
}
}
}
)
}
}
Is there a faster/better way to do this?
Javascript for dynamically revealing Django formset forms
I’m trying to add/remove forms from formsets dynamically on button press. I am looking at an older example for JS to perform this action but I have multiple formsets but when I delete all of the forms for one of the formsets, obviously the addForm command no longer works as there are no forms to clone.
That being said, I think a functional method would be to start with a hidden form and then copy the hidden form and display that form on demand. I just don’t know how exactly to do that.
Ideally, I’d like to not show any forms until the button press but not certain about how to do it. My current setup is shown below.
HTML:
<div class="selection">
<div class="forms">
<!-- {% for dict in formset.errors %}
{% for error in dict.values %}
{{ error }}
{% endfor %}
{% endfor %} -->
<form id="general-formset" method="POST">
{% csrf_token %}
{{ generalFormset.management_form }}
{% for form in generalFormset %}
<div class="formset">
{{ form.as_table }}
<button id="remove-form" type="button" onclick="removeForm(this)" display="None">Remove Constraint</button>
</div>
{% endfor %}
<button id="add-form" type="button" onclick="addForm(this)">Add Constraint</button>
</form>
<form id="specific-formset" method="POST">
{% csrf_token %}
{{ specificFormset.management_form }}
{% for form in specificFormset %}
<div class="formset">
{{ form.as_table }}
<button id="remove-form" type="button" onclick="removeForm(this)">Remove Constraint</button>
</div>
{% endfor %}
<button id="add-form" type="button" onclick="addForm(this)" display="None">Add Constraint</button>
</form>
<button id="submit" type="button">Submit</button>
</div>
</div>
JavaScript:
<script>
let submitButton = document.querySelector("#submit")
submitButton.addEventListener('click', submitForms)
function submitForms(e){
document.getElementById("specific-formset").submit();
document.getElementById("general-formset").submit();
}
function addForm(e){
let container = e.parentElement
let form = container.querySelectorAll(".formset")[0].cloneNode(true)
let formNum = container.querySelectorAll(".formset").length-1
let formRegex = RegExp(`form-(\d){1}-`,'g')
let totalForms = container.querySelector("#id_form-TOTAL_FORMS")
formNum++
form.innerHTML = form.innerHTML.replace(formRegex, `form-${formNum}-`)
container.insertBefore(form, e)
totalForms.setAttribute('value', `${formNum+1}`)
}
function removeForm(e){
let parent = e.parentElement
let container = parent.parentElement
let formNum = container.querySelectorAll(".formset").length-1
let totalForms = container.querySelector("#id_form-TOTAL_FORMS")
parent.remove()
formNum--
totalForms.setAttribute('value', `${formNum-1}`)
}
</script>
How to delete object properties based on another interface?
how can I to automatically delete family property? or at least I want to get an error tells class A is not compatible with B.
class A {
name? : string; family : string = "bye";
}
class B {
name? : string;
}
let b : B = new A();
b.name ="hiii";
//b.family = "something" <--- error, which is intended, but the variable still exist...
console.log({...b})
output:
{
"family": "bye",
"name": "hiii"
}
my goal:
{
"name": "hiii"
}
I’m using the spread operator to INSERT items into an sql table, and I want to make sure I have only the defined properties. I can manually map them, but is there no out-of-the-box solution?
thanks for any help attempt.
Note: Utility Types such as Pick and Required will not help since the question here is not about types
How to make this code as a library to use in main code
I have made a code to read data from a device then confert the data to be readable. Now my co-worker told me to make it as a library so he can get the data from it, but I just learn javascript and node.js so I don’t know how.
This is my code:
// create an empty modbus client
const ModbusRTU = require("modbus-serial");
const client = new ModbusRTU();
let timeoutRunRefHoldings = null;
// open connection to a serial port
client.connectRTUBuffered("/dev/ttyUSB0", { baudRate: 9600 })
.then(setClient1)
.then(function() {
console.log("Connected"); })
async function setClient1() {
// set the client's unit id
// set a timout for requests default is null (no timeout)
client.setID(1);
// run program
console.log("Flow rate:", await ReadReg(0,2) + " m³/h");
console.log("Velocity:", await ReadReg(4,2) + " m/s"),
console.log("Fluid sound speed:", await ReadReg(6,2) + " m/s");
console.log("Temperature #1/inlet:", await ReadReg(32,2) + " °C");
console.log("Temperature #2/inlet:", await ReadReg(34,2) + " °C");
}
async function ReadReg(addr, len) {
let regVal = await client.readHoldingRegisters(addr, len)
return REAL4(...regVal.data)
}
function REAL4(reg1, reg2){
// i) Convert the first register into binary
const value1=parseInt(reg1,10);
var binaryVl1=value1.toString(2);
while (binaryVl1.length < 16) {
binaryVl1 = '0'+binaryVl1;
}
// ii) Convert the second register into binary
const value2=parseInt(reg2,10);
var binaryVl2=value2.toString(2);
while (binaryVl2.length < 16) {
binaryVl2 = '0'+binaryVl2;
}
// iii) Combine Reg1 & Reg2
const combine=binaryVl2+binaryVl1;
const cb16x=(parseInt(combine, 2)).toString(16);
const buffer = new ArrayBuffer(4);
const bytes = new Uint8Array(buffer);
bytes[0] = '0x'+cb16x.substring(0,2);
bytes[1] = '0x'+cb16x.substring(2,4);
bytes[2] = '0x'+cb16x.substring(4,6);
bytes[3] = '0x'+cb16x.substring(6);
// iv) Convert combine into float(IEEE 754 floating point)
var view = new DataView(buffer);
const result=(view.getFloat32(0, false)).toPrecision(6);
return(result);
}
So, if I have to make it into a library should I remove console.log ?
I really don’t know anything about libraries.
Unable to Fetch file larger than 40 MB in javascript
Unable to fetch files greater than ~ 40 MB using the fetch() web api
A sample of my code :-
fetch("big.file.50MB")
.then(res => res.blob())
.then(dlBlob) // function to download blob using createObjectURL
.catch(console.error)
OutPut :
Uncaught (in promise) TypeError: Failed to fetch
But, if file is less than 40 – 35 MB it downloads perfectly…
