Jquery Clone Not Functioning As Expected
I am working on a program that is not functioning as I am expecting it. I have a page that allows people to add multiple links to my application, but there is something going on un
Solution 1:
@Mathew Try this
$('.section-group-js').on('keyup', 'input[type="url"]', function() {
var section = $(this).closest('section');
if (section.is(':last-child')) {
var index = section.data('index');
var newSection = section.clone();
newSection.find('input').val('');
newSection.data('index', index + 1);
newSection.attr('data-index', index + 1);
updateAttributes(newSection, 'title', index);
updateAttributes(newSection, 'url', index);
updateAttributes(newSection, 'visible', index);
newSection.insertAfter(section);
}
})
functionupdateAttributes( newSection, key, index ) {
newSection.find(`[name="attach[${index}][${key}]"]`).attr('name', `attach[${index+1}][${key}]`);
}
.modal {
display: block !Important
}
.modal {
display: none;
position: fixed;
z-index: 20;
right: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
-webkit-animation-name: fadeIn;
-webkit-animation-duration: 0.4s;
animation-name: fadeIn;
animation-duration: 0.4s
}
.assignment-window {
display: grid;
position: fixed;
overflow: hidden;
padding: 10px;
padding-bottom: 16px;
box-sizing: border-box;
width: 100vw;
height: 85vh;
bottom: 0;
left: 0;
border-top-left-radius: 40px;
border-top-right-radius: 40px;
background-color: white;
grid-template-rows: auto 1fr;
grid-template-columns: 0.9fr 2.5fr;
grid-template-areas: "asstop asstop""assnav asscontent"
}
/* ----------[ASS TOP]---------- */.asstop {
grid-area: asstop;
padding: 24px20px;
box-sizing: border-box;
border-bottom: 2px solid #581F98;
}
.asstop.title {
display: flex;
align-items: center;
}
.asstop.titleinput {
flex: 11;
font-size: 24px;
border-radius: 8px;
margin-right: 20px;
border: 1px solid lightgray
}
.asstop select {
outline: none;
-webkit-appearance: none;
padding: 12px16px;
font-size: 24px;
box-sizing: border-box;
border-radius: 8px;
border: 1px solid lightgray
}
.asstopbutton {
margin-top: -5px;
}
/* ----------[ASS NAV]---------- */.assnav {
grid-area: assnav;
padding-top: 20px;
padding-right: 10%;
border-right: 1px solid lightgray
}
.assnavul {
margin: 0;
padding: 0;
overflow: hidden;
list-style-type: none
}
.assnavli {
display: block;
text-decoration: none;
color: #484848;
font-size: 20px;
padding: 14px20px;
margin-bottom: 10px;
border-top-right-radius: 40px;
border-bottom-right-radius: 40px;
}
.assnavli:hover {
background-color: #F2F2F2
}
.assnavli.active {
background-color: #EEEEEE
}
/* ----------[ASS CONTENT]---------- */.asscontent {
grid-area: asscontent;
display: flex;
flex-direction: column;
padding: 30px;
box-sizing: border-box;
}
.asscontentinput,
.asscontent select {
flex: 1;
outline: none;
-webkit-appearance: none;
padding: 8px16px;
font-size: 18px;
box-sizing: border-box;
border-radius: 8px;
border: 1px solid lightgray
}
/* ==== Basic Styling ==== */.asscontent.basic {
display: none
}
.asscontent.basictextarea {
flex: 1;
font-size: 18px;
border-radius: 8px;
box-sizing: border-box;
}
.asscontent.basic.config {
display: flex;
justify-content: space-between;
padding-top: 20px;
}
.asscontent.basicinput {
text-align: center;
}
.asscontent.basic.points {
width: 80px;
}
/* ==== Attachment Styling ==== */.asscontent.attachmentssection {
display: flex;
justify-content: space-between;
padding-bottom: 15px;
margin-bottom: 15px;
border-bottom: 1px solid lightgray
}
<head><linkrel="stylesheet"href="https://classcolonies.com/resources/style.css"><linkhref="https://fonts.googleapis.com/css2?family=Raleway&display=swap"rel="stylesheet"><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><nav></nav></head><divclass="modal"><formmethod="post"action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<divclass="assignment-window"><divclass='asstop'><divclass='title'><select><option>✏️</option><option>๐ป</option><option>๐</option><option>๐ฏ</option><option>๐งช</option></select><inputtype='text'placeholder='Type assignment title..'value=''><buttontype="submit"class='button purple-btn'>Save Changes</button></div></div><divclass='assnav'><ul><li>Basic Setup</li><li>Attachments</li><li>Advanced Settings</li><li>Delete Assignment</li></ul></div><divclass='asscontent'><divclass='attachments section-group-js'><sectiondata-index="1"><divclass='displayName'><span> Title: </span><inputname='attach[1][title]'type='text'></div><divclass='url'><span>URL: <span><inputname='attach[1][url]'type='url'></div><divclass='visible'><span>Visible: <span><selectname='attach[1][visible]'><option>- All Students -</option><option>๐ฃ Reading/Social</option></select></div></section></div></div></div></form></div>
<?phpif ( isset($_POST['attach']) ) {
echo"<pre>";
print_r($_POST);
echo"</pre>";
die;
}
?>
And the output is below
Post a Comment for "Jquery Clone Not Functioning As Expected"