Skip to content
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

Email, date and url fields are validated #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion meta_creator/templates/meta_creator/showdata.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h3 class="mainHeader">Metadata Extractor Tool</h3>
{% csrf_token %}
{% for key, value in extracted_metadata.items %}
<div class="form-group">

{% if value|list and key == "programmingLanguage" %}
<div class="single_inputs">
<label title="{% with descriptions=entered_data.description_dict %}{% if key in descriptions %}{{ descriptions|get:key }}{% endif %}{% endwith %}">Programming Language</label>
Expand All @@ -37,6 +38,7 @@ <h3 class="mainHeader">Metadata Extractor Tool</h3>
<label title="{% with descriptions=entered_data.description_dict %}{% if key in descriptions %}{{ descriptions|get:key }}{% endif %}{% endwith %}">Keywords</label>
<input name="{{ key }}" type="text" value="{% for item in value %}{% if item %}{{ item }}, {% endif %}{% endfor %}">
</div>

{% elif value|is_dict and key == "copyrightHolder" %}
<fieldset class="copyrightHolder">
<legend title="{% with descriptions=entered_data.description_dict %}{% if key in descriptions %}{{ descriptions|get:key }}{% endif %}{% endwith %}">Copyright Holder Name</legend>
Expand All @@ -47,6 +49,12 @@ <h3 class="mainHeader">Metadata Extractor Tool</h3>
{% endif %}
{% endfor %}
</fieldset>

{% elif key == "dateCreated" or key == "dateModified"%}
<div class="single_inputs">
<label title="{% with descriptions=entered_data.description_dict %}{% if key in descriptions %}{{ descriptions|get:key }}{% endif %}{% endwith %}">{{key}}</label>
<input name="{{ key }}" type="date" value="{{value}}" placeholder="YYYY-MM-DD" >
</div>

{% elif key == "author" %}
<table class="authors-table">
Expand Down Expand Up @@ -141,7 +149,7 @@ <h3 class="mainHeader">Metadata Extractor Tool</h3>
{% csrf_token %}
<h4>Metadata</h4>
<div class="metadata-container">
<button class="ExData" id="downloadButton" title="Download the JSON file." onclick="downloadFile()">Download JSON</button>
<button class="ExData" id="downloadButton" title="Download the JSON file.">Download JSON</button>
<p>Metadata as JSON:</p>
<textarea name="txtareaJSON" id="metadata-json">{{ my_json_str }}</textarea>
</div>
Expand Down
72 changes: 67 additions & 5 deletions static/foundation/js/vendor/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,27 @@ document.addEventListener("DOMContentLoaded", function () {
const inputs = document.querySelectorAll("#metadata-form input");
const deleteButtons = document.querySelectorAll('[data-action="delete"]');

document.getElementById('addContributorButton').addEventListener('click', function () {
addPerson('contributor', 'contributorsTableBody', ['Email']);
});

document.getElementById('addContributorButton').addEventListener('click', function () {
// Get the email input value
var email = document.getElementById('contributorEmailInput').value;

// Regular expression for basic email validation
var emailPattern = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

// Validate the email
if (emailPattern.test(email)) {
// If email is valid, proceed to add the person
addPerson('contributor', 'contributorsTableBody', ['Email']);
} else {
// If email is not valid, show an error message
alert('Please enter a valid email address.');
}
});
document.getElementById('addAuthorButton').addEventListener('click', function () {
addPerson('author', 'authorsTableBody', []);
});


function handleTableClick(tableBody, editCallback, deleteCallback) {
tableBody.addEventListener('click', function (event) {
Expand Down Expand Up @@ -312,10 +325,59 @@ function downloadFile(event) {
link.parentNode.removeChild(link); // remove the link element from the DOM
}, 0);
}
function validateURL(id) {

// Get the input value
var url = document.getElementById(id).value;

// Regular expression for basic email validation
var urlPattern = /^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(:\d+)?(\/.*)?$/;

if (urlPattern.test(url)) {
return true;
} else {

return false;
}


}

// add event listener to download button
downloadButton.addEventListener("click", (event) => {
downloadFile(event);
urlFieldID='url-';
codeRepository='codeRepository-';
issueTracker='issueTracker-';
downloadUrl='downloadUrl-'
readme='readme-';
if(validateURL(urlFieldID)==false){
alert('url in Url field is not correct');
return false;
}
else if (validateURL(codeRepository)==false){
alert('url in codeRepository field is not correct');
return false;
}
else if (validateURL(issueTracker)==false){
alert('url in issueTracker field is not correct');
return false;
}
else if (validateURL(codeRepository)==false){
alert('url in codeRepository field is not correct');
return false;
}
else if (validateURL(downloadUrl)==false){
alert('url in downloadUrl field is not correct');
return false;
}
else if (validateURL(readme)==false){
alert('url in readme field is not correct');
return false;
}

else{
downloadFile(event);
}
});

});
Expand Down
Loading